mirror of https://github.com/helix-editor/helix
Fix clamping scroll in certain cases.
.clamp(min, max) requires that min < max. In some cases first + scrolloff > last - scrolloff and we would panic.pull/11/head
parent
5aed1f3c00
commit
463f58dfda
|
@ -462,10 +462,9 @@ fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
|
||||||
.min(doc_last_line);
|
.min(doc_last_line);
|
||||||
|
|
||||||
// clamp into viewport
|
// clamp into viewport
|
||||||
let line = (view.first_line + cursor_off).clamp(
|
let line = (view.first_line + cursor_off)
|
||||||
view.first_line + scrolloff,
|
.max(view.first_line + scrolloff)
|
||||||
last_line.saturating_sub(scrolloff),
|
.min(last_line.saturating_sub(scrolloff));
|
||||||
);
|
|
||||||
|
|
||||||
let text = doc.text().slice(..);
|
let text = doc.text().slice(..);
|
||||||
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…
Reference in New Issue