on master help sign in
Fix cursor jumping when we're positioned in top padding pressing up.
03795e5Blaž Hrastnik
helix-view/src/commands.rs+10−2
@@ -147,11 +147,15 @@ pub fn check_cursor_in_view(view: &mut View) -> bool {
147}
147}
148
148
149pub fn page_up(view: &mut View, _count: usize) {
149pub fn page_up(view: &mut View, _count: usize) {
150+ if view.first_line < PADDING {
151+ return;
152+ }
153+
150 view.first_line = view.first_line.saturating_sub(view.size.1 as usize);
154 view.first_line = view.first_line.saturating_sub(view.size.1 as usize);
151
155
152 if !check_cursor_in_view(view) {
156 if !check_cursor_in_view(view) {
153 let text = view.state.doc();
157 let text = view.state.doc();
154− let pos = text.line_to_char(view.last_line().saturating_sub(PADDING as usize));
158+ let pos = text.line_to_char(view.last_line().saturating_sub(PADDING));
155 view.state.selection = Selection::single(pos, pos);
159 view.state.selection = Selection::single(pos, pos);
156 }
160 }
157}
161}
@@ -167,11 +171,15 @@ pub fn page_down(view: &mut View, _count: usize) {
167}
171}
168
172
169pub fn half_page_up(view: &mut View, _count: usize) {
173pub fn half_page_up(view: &mut View, _count: usize) {
174+ if view.first_line < PADDING {
175+ return;
176+ }
177+
170 view.first_line = view.first_line.saturating_sub(view.size.1 as usize / 2);
178 view.first_line = view.first_line.saturating_sub(view.size.1 as usize / 2);
171
179
172 if !check_cursor_in_view(view) {
180 if !check_cursor_in_view(view) {
173 let text = &view.state.doc;
181 let text = &view.state.doc;
174− let pos = text.line_to_char(view.last_line() - PADDING as usize);
182+ let pos = text.line_to_char(view.last_line() - PADDING);
175 view.state.selection = Selection::single(pos, pos);
183 view.state.selection = Selection::single(pos, pos);
176 }
184 }
177}
185}