commit 0e30177db7c0cc376d865cfe13072a816a73b0d5
parent 3089a98169708edeea6b4afc84ec3eda11043ba1
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sat, 10 Mar 2018 12:41:08 +0100
scrolling: let Scroll-Up/Down keep the cursor in the same text position
Instead of keeping the cursor in the same spot on the screen,
let the cursor move with the text (whenever possible).
This makes these functions behave the same as in Vim and Emacs.
Diffstat:
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/src/move.c b/src/move.c
@@ -493,17 +493,18 @@ void do_up(bool scroll_only)
openfile->firstcolumn == 0)
return;
+ if (scroll_only)
+ edit_scroll(BACKWARD);
+
get_edge_and_target(&leftedge, &target_column);
/* If we can't move up one line or chunk, we're at top of file. */
- if (go_back_chunks(1, &openfile->current, &leftedge) > 0)
+ if ((!scroll_only || openfile->current_y == editwinrows - 1) &&
+ go_back_chunks(1, &openfile->current, &leftedge) > 0)
return;
set_proper_index_and_pww(&leftedge, target_column, FALSE);
- if (scroll_only)
- edit_scroll(BACKWARD);
-
edit_redraw(was_current, FLOWING);
/* <Up> should not change placewewant, so restore it. */
@@ -517,17 +518,19 @@ void do_down(bool scroll_only)
filestruct *was_current = openfile->current;
size_t leftedge, target_column;
+ if (scroll_only && (openfile->current_y > 0 ||
+ openfile->current != openfile->filebot))
+ edit_scroll(FORWARD);
+
get_edge_and_target(&leftedge, &target_column);
/* If we can't move down one line or chunk, we're at bottom of file. */
- if (go_forward_chunks(1, &openfile->current, &leftedge) > 0)
+ if ((!scroll_only || openfile->current_y == 0) &&
+ go_forward_chunks(1, &openfile->current, &leftedge) > 0)
return;
set_proper_index_and_pww(&leftedge, target_column, TRUE);
- if (scroll_only)
- edit_scroll(FORWARD);
-
edit_redraw(was_current, FLOWING);
/* <Down> should not change placewewant, so restore it. */