MCPcopy Create free account
hub / github.com/Eeive/Evcode-ide / char_to_position

Method char_to_position

src/editor/document.rs:82–89  ·  view source on GitHub ↗
(&self, char_idx: usize)

Source from the content-addressed store, hash-verified

80 }
81
82 pub fn char_to_position(&self, char_idx: usize) -> (usize, usize) {
83 let char_idx = char_idx.min(self.len_chars());
84 let line = self.char_to_line(char_idx);
85 let line_start = self.line_to_char(line);
86 let prefix = self.slice_text(line_start, char_idx);
87 let column = prefix.graphemes(true).count();
88 (line, column.min(self.line_len_chars(line)))
89 }
90
91 pub fn char_at(&self, char_idx: usize) -> Option<char> {
92 (char_idx < self.len_chars()).then(|| self.rope.char(char_idx))

Callers 2

delete_char_backwardMethod · 0.80

Calls 5

len_charsMethod · 0.80
char_to_lineMethod · 0.80
line_to_charMethod · 0.80
slice_textMethod · 0.80
line_len_charsMethod · 0.45

Tested by

no test coverage detected