From 8374552715631561c0248595dbe909ebb480d3c7 Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 4 Aug 2022 02:22:20 +0200 Subject: [PATCH] Fix cursor moving out of bounds On a long line ending with whitespace, the cursor would be able to move out of bounds if there was enough whitespace. --- src/ui/widgets/editor.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ui/widgets/editor.rs b/src/ui/widgets/editor.rs index 7221f6e..3ba0042 100644 --- a/src/ui/widgets/editor.rs +++ b/src/ui/widgets/editor.rs @@ -276,6 +276,7 @@ impl Widget for Editor { let (cursor_row, cursor_line_idx) = Self::wrapped_cursor(self.idx, &indices); let cursor_col = frame.width(lines[cursor_row].text().split_at(cursor_line_idx).0); + let cursor_col = cursor_col.min(text_width); frame.set_cursor(Some(Pos::new(cursor_col as i32, cursor_row as i32))); for (i, line) in lines.into_iter().enumerate() {