on master help sign in
Fix clamping scroll in certain cases.

.clamp(min, max) requires that min < max. In some cases first + scrolloff > last - scrolloff and we would panic.

commit463f58dfda3d72865860e53759ab001c94a85989 authorBlaž Hrastnik <blaz@mxxn.io> dateWed 7 Apr 2021, 13:38 (6 years ago) parent5aed1f3
1 file changed+3−4
helix-term/src/commands.rs+3−4
helix-term/src/commands.rs+3−4
@@ -462,10 +462,9 @@ fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
462462 .min(doc_last_line);
463463
464464 // clamp into viewport
465− let line = (view.first_line + cursor_off).clamp(
466− view.first_line + scrolloff,
467− last_line.saturating_sub(scrolloff),
468− );
465+ let line = (view.first_line + cursor_off)
466+ .max(view.first_line + scrolloff)
467+ .min(last_line.saturating_sub(scrolloff));
469468
470469 let text = doc.text().slice(..);
471470 let pos = pos_at_coords(text, Position::new(line, cursor.col)); // this func will properly truncate to line end