Fix a scrolling crash where it would jump past the end of the buffer.

pull/11/head
Blaž Hrastnik 4 years ago
parent 73c92a0bc1
commit d0530fb839

@ -54,6 +54,7 @@ fn next_char(doc: &Rope, pos: usize) -> Option<char> {
} }
Some(doc.char(pos)) Some(doc.char(pos))
} }
// TODO: selections should be extended if range, moved if point.
// TODO: if not cursor but selection, wrap on both sides of selection (surround) // TODO: if not cursor but selection, wrap on both sides of selection (surround)
fn handle_open( fn handle_open(

@ -433,7 +433,7 @@ fn scroll(view: &mut View, offset: usize, direction: Direction) {
// clamp into viewport // clamp into viewport
let line = (view.first_line + cursor_off).clamp( let line = (view.first_line + cursor_off).clamp(
view.first_line + scrolloff, view.first_line + scrolloff,
view.first_line + view.last_line().saturating_sub(scrolloff), view.last_line().saturating_sub(scrolloff),
); );
let pos = pos_at_coords(text, Position::new(line, cursor.col)); // this func will properly truncate to line end let pos = pos_at_coords(text, Position::new(line, cursor.col)); // this func will properly truncate to line end

Loading…
Cancel
Save