diff options
author | Blaž Hrastnik | 2021-04-14 05:27:47 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-04-14 05:27:47 +0000 |
commit | 180521fefec8923bd4082c4a1e9beca599a44d07 (patch) | |
tree | 0cf2db542a8b011f139ae5cac69e8faec8b5e258 /helix-term/src | |
parent | dfb1ae2d3342d578aee10152ac6bbbb407f25f9c (diff) |
Adjust scroll() to match kakoune: only scroll the view if cursor in bounds.
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/commands.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index f1c5f8b5..190ae3b9 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -450,10 +450,11 @@ fn scroll(cx: &mut Context, offset: usize, direction: Direction) { return; } - let scrolloff = PADDING; // min(user pref, half win width/height) + let scrolloff = PADDING.min(view.area.height as usize / 2); // TODO: user pref // cursor visual offset - let cursor_off = cursor.row - view.first_line; + // TODO: only if dragging via mouse? + // let cursor_off = cursor.row - view.first_line; view.first_line = match direction { Forward => view.first_line + offset, @@ -461,14 +462,19 @@ fn scroll(cx: &mut Context, offset: usize, direction: Direction) { } .min(doc_last_line); + // recalculate last line + let last_line = view.last_line(doc); + // clamp into viewport - let line = (view.first_line + cursor_off) - .max(view.first_line + scrolloff) - .min(last_line.saturating_sub(scrolloff)); + let line = cursor.row.clamp( + view.first_line + scrolloff, + 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 + // TODO: only manipulate main selection doc.set_selection(view.id, Selection::point(pos)); } |