From 51d03c6fe2e169c5af6cff38a1172770f6f65085 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 7 Aug 2022 00:01:27 +0200 Subject: [PATCH] Fix moving to end of last line --- src/ui/widgets/editor.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ui/widgets/editor.rs b/src/ui/widgets/editor.rs index e8a3d6e..20f4a38 100644 --- a/src/ui/widgets/editor.rs +++ b/src/ui/widgets/editor.rs @@ -141,16 +141,19 @@ impl InnerEditorState { let (start, end) = self.line(line); let line = &self.text[start..end]; - self.idx = start; let mut width = 0; for (gi, g) in line.grapheme_indices(true) { self.idx = start + gi; if col > width { width += frame.grapheme_width(g, width) as usize; } else { - break; + return; } } + + if !line.ends_with('\n') { + self.idx = end; + } } fn record_cursor_col(&mut self, frame: &mut Frame) {