diff options
author | Joscha <joscha@plugh.de> | 2022-09-08 22:05:46 +0200 |
---|---|---|
committer | Joscha <joscha@plugh.de> | 2022-09-08 22:05:46 +0200 |
commit | f49481cb103ad9bba4aca6fc70eb1288b991ce6b (patch) | |
tree | 10aacff46d15dbbcfb6f33c9e2db2984ab6a2fd6 | |
parent | 9876dd67a735a0d394adf207014e70589ef36ea8 (diff) |
Fix cursor disappearing in editor
-rw-r--r-- | src/ui/widgets/editor.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/ui/widgets/editor.rs b/src/ui/widgets/editor.rs index ff4a183..c90f6ee 100644 --- a/src/ui/widgets/editor.rs +++ b/src/ui/widgets/editor.rs @@ -526,17 +526,24 @@ impl Widget for Editor { let indices = wrap(frame, self.text.text(), text_width); let lines = self.text.split_at_indices(&indices); - if self.focus { + // Determine cursor position now while we still have the lines. + let cursor_pos = if self.focus { 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))); - } + Some(Pos::new(cursor_col as i32, cursor_row as i32)) + } else { + None + }; for (i, line) in lines.into_iter().enumerate() { frame.write(Pos::new(0, i as i32), line); } + if let Some(pos) = cursor_pos { + frame.set_cursor(Some(pos)); + } + self.state.lock().last_width = width; } } |