From 625c8d11f48e4f76f559559021c057479dc0652d Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Mon, 4 May 2020 06:17:38 +0530 Subject: [PATCH] Refactor move_cursor() --- plugins/finder | 2 +- plugins/mimelist | 2 +- src/nnn.c | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/finder b/plugins/finder index c3b22420..b7cda420 100755 --- a/plugins/finder +++ b/plugins/finder @@ -6,7 +6,7 @@ # - export FZF_DEFAULT_OPTS='--bind ctrl-a:select-all,ctrl-d:deselect-all' # # Shell: POSIX compliant -# Author: Arun Prakash jana +# Author: Arun Prakash Jana . "$(dirname "$0")"/.nnn-plugin-helper diff --git a/plugins/mimelist b/plugins/mimelist index 5635afda..f179e6e3 100755 --- a/plugins/mimelist +++ b/plugins/mimelist @@ -4,7 +4,7 @@ # Requires: fd/find # # Shell: POSIX compliant -# Author: Arun Prakash jana +# Author: Arun Prakash Jana . "$(dirname "$0")"/.nnn-plugin-helper diff --git a/src/nnn.c b/src/nnn.c index 6c46db00..1a2ad77f 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -4669,15 +4669,17 @@ static void populate(char *path, char *lastname) static void move_cursor(int target, int ignore_scrolloff) { - int delta, scrolloff, onscreen = xlines - 4; + int onscreen = xlines - 4; /* Leave top 2 and bottom 2 lines */ - last_curscroll = curscroll; target = MAX(0, MIN(ndents - 1, target)); - delta = target - cur; + last_curscroll = curscroll; last = cur; cur = target; + if (!ignore_scrolloff) { - scrolloff = MIN(SCROLLOFF, onscreen >> 1); + int delta = target - last; + int scrolloff = MIN(SCROLLOFF, onscreen >> 1); + /* * When ignore_scrolloff is 1, the cursor can jump into the scrolloff * margin area, but when ignore_scrolloff is 0, act like a boa