Fix moving to end of last line

This commit is contained in:
Joscha 2022-08-07 00:01:27 +02:00
parent 4bf6d80988
commit 51d03c6fe2

View file

@ -141,16 +141,19 @@ impl InnerEditorState {
let (start, end) = self.line(line); let (start, end) = self.line(line);
let line = &self.text[start..end]; let line = &self.text[start..end];
self.idx = start;
let mut width = 0; let mut width = 0;
for (gi, g) in line.grapheme_indices(true) { for (gi, g) in line.grapheme_indices(true) {
self.idx = start + gi; self.idx = start + gi;
if col > width { if col > width {
width += frame.grapheme_width(g, width) as usize; width += frame.grapheme_width(g, width) as usize;
} else { } else {
break; return;
} }
} }
if !line.ends_with('\n') {
self.idx = end;
}
} }
fn record_cursor_col(&mut self, frame: &mut Frame) { fn record_cursor_col(&mut self, frame: &mut Frame) {