nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH] browser: keep the highlight in the same spot or col


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH] browser: keep the highlight in the same spot or column, when possible
Date: Wed, 11 May 2016 19:15:54 +0200

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.
---
 src/browser.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/browser.c b/src/browser.c
index 78d692a..34b37e7 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -191,14 +191,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) {
-- 
2.8.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]