commit 58404e4ba295516c14848e80345572db702bf780
parent 36df5ceef65b34cc4738f5bdd29390545740237f
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Wed, 11 May 2016 13:29:38 +0200
browser: keep the highlight in the same spot or column, when possible
When doing a PageUp or PageDown in the browser, don't move the highlight
to the first line in the same column, but keep it in the same relative
position of the screen. If we're already on the first or last page,
move the highlight to the first or last line, but keep it in the same
column. If we're already on the first or last line, only then move it
to the first or last entry.
Diffstat:
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/browser.c b/src/browser.c
@@ -187,14 +187,20 @@ char *do_browser(char *path, DIR *dir)
/* Search for another filename. */
do_fileresearch();
} else if (func == do_page_up) {
- if (selected >= (editwinrows + fileline % editwinrows) * width)
- selected -= (editwinrows + fileline % editwinrows) * width;
- else
+ if (selected < width)
selected = 0;
+ else if (selected < editwinrows * width)
+ selected = selected % width;
+ else
+ selected -= editwinrows * width;
} else if (func == do_page_down) {
- selected += (editwinrows - fileline % editwinrows) * width;
- if (selected > filelist_len - 1)
+ if (selected + width >= filelist_len - 1)
selected = filelist_len - 1;
+ else if (selected + editwinrows * width >= filelist_len)
+ selected = (selected + editwinrows * width - filelist_len) %
+ width + filelist_len - width;
+ else
+ selected += editwinrows * width;
} else if (func == do_first_file) {
selected = 0;
} else if (func == do_last_file) {