aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-04-07 04:38:50 +0000
committerBlaž Hrastnik2021-04-07 04:38:50 +0000
commit463f58dfda3d72865860e53759ab001c94a85989 (patch)
tree485705d9d90876b4502c6d341402945d11b6521b
parent5aed1f3c0049d7c00729c8a5e09ba1dc497d037c (diff)
Fix clamping scroll in certain cases.
.clamp(min, max) requires that min < max. In some cases first + scrolloff > last - scrolloff and we would panic.
-rw-r--r--helix-term/src/commands.rs7
1 files changed, 3 insertions, 4 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 4d9c24a0..b79f3b79 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -462,10 +462,9 @@ fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
.min(doc_last_line);
// clamp into viewport
- let line = (view.first_line + cursor_off).clamp(
- view.first_line + scrolloff,
- last_line.saturating_sub(scrolloff),
- );
+ let line = (view.first_line + cursor_off)
+ .max(view.first_line + scrolloff)
+ .min(last_line.saturating_sub(scrolloff));
let text = doc.text().slice(..);
let pos = pos_at_coords(text, Position::new(line, cursor.col)); // this func will properly truncate to line end