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.
This commit is contained in:
Joscha 2022-08-04 02:22:20 +02:00
parent 20ea96f83e
commit 8374552715

View file

@ -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() {