From 03795e56742e5a6047e63467ef2912c2306c112d Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Wed, 7 Oct 2020 14:15:32 +0900 Subject: Fix cursor jumping when we're positioned in top padding pressing up. --- helix-view/src/commands.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs index 19853c37..18135f0f 100644 --- a/helix-view/src/commands.rs +++ b/helix-view/src/commands.rs @@ -147,11 +147,15 @@ pub fn check_cursor_in_view(view: &mut View) -> bool { } pub fn page_up(view: &mut View, _count: usize) { + if view.first_line < PADDING { + return; + } + view.first_line = view.first_line.saturating_sub(view.size.1 as usize); if !check_cursor_in_view(view) { let text = view.state.doc(); - let pos = text.line_to_char(view.last_line().saturating_sub(PADDING as usize)); + let pos = text.line_to_char(view.last_line().saturating_sub(PADDING)); view.state.selection = Selection::single(pos, pos); } } @@ -167,11 +171,15 @@ pub fn page_down(view: &mut View, _count: usize) { } pub fn half_page_up(view: &mut View, _count: usize) { + if view.first_line < PADDING { + return; + } + view.first_line = view.first_line.saturating_sub(view.size.1 as usize / 2); if !check_cursor_in_view(view) { let text = &view.state.doc; - let pos = text.line_to_char(view.last_line() - PADDING as usize); + let pos = text.line_to_char(view.last_line() - PADDING); view.state.selection = Selection::single(pos, pos); } } -- cgit v1.2.3-70-g09d2