aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-10-19 09:01:23 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-10-19 09:10:52 +0530
commit95e9151c90a515b85a5243ce28ac0cdd26f5a0c6 (patch)
tree458c19fff183d6405f19c236719b6880e84c2d44 /src
parent864273dd9b8d0af7366710b528684fce358baf00 (diff)
downloadnnn-95e9151c90a515b85a5243ce28ac0cdd26f5a0c6.tar.gz
Refactor screen move
Diffstat (limited to 'src')
-rw-r--r--src/nnn.c95
1 files changed, 51 insertions, 44 deletions
diff --git a/src/nnn.c b/src/nnn.c
index 146765e..cfee8dd 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -3637,6 +3637,48 @@ static void move_cursor(int target, int ignore_scrolloff)
curscroll = MAX(curscroll, MAX(cur - (onscreen - 1), 0));
}
+static void handle_screen_move(enum action sel)
+{
+ int onscreen;
+
+ switch (sel) {
+ case SEL_NEXT:
+ if (ndents)
+ move_cursor((cur + 1) % ndents, 0);
+ break;
+ case SEL_PREV:
+ if (ndents)
+ move_cursor((cur + ndents - 1) % ndents, 0);
+ break;
+ case SEL_PGDN:
+ onscreen = xlines - 4;
+ move_cursor(curscroll + (onscreen - 1), 1);
+ curscroll += onscreen - 1;
+ break;
+ case SEL_CTRL_D:
+ onscreen = xlines - 4;
+ move_cursor(curscroll + (onscreen - 1), 1);
+ curscroll += onscreen >> 1;
+ break;
+ case SEL_PGUP: // fallthrough
+ onscreen = xlines - 4;
+ move_cursor(curscroll, 1);
+ curscroll -= onscreen - 1;
+ break;
+ case SEL_CTRL_U:
+ onscreen = xlines - 4;
+ move_cursor(curscroll, 1);
+ curscroll -= onscreen >> 1;
+ break;
+ case SEL_HOME:
+ move_cursor(0, 1);
+ break;
+ default: /* case SEL_END: */
+ move_cursor(ndents - 1, 1);
+ break;
+ }
+}
+
static void redraw(char *path)
{
xlines = LINES;
@@ -3803,7 +3845,7 @@ static void browse(char *ipath, const char *session)
char rundir[PATH_MAX] __attribute__ ((aligned));
char runfile[NAME_MAX + 1] __attribute__ ((aligned));
uchar opener_flags = (cfg.cliopener ? F_CLI : (F_NOTRACE | F_NOWAIT));
- int r = -1, fd, presel, selstartid = 0, selendid = 0, onscreen;
+ int r = -1, fd, presel, selstartid = 0, selendid = 0;
ino_t inode = 0;
enum action sel;
bool dir_changed = FALSE, rangesel = FALSE;
@@ -4089,50 +4131,15 @@ nochange:
printwait("unsupported file", &presel);
goto nochange;
}
- case SEL_NEXT: // fallthorugh
- case SEL_PREV: // fallthorugh
- case SEL_PGDN: // fallthorugh
- case SEL_CTRL_D: // fallthorugh
- case SEL_PGUP: // fallthorugh
- case SEL_CTRL_U: // fallthorugh
- case SEL_HOME: // fallthorugh
+ case SEL_NEXT: // fallthrough
+ case SEL_PREV: // fallthrough
+ case SEL_PGDN: // fallthrough
+ case SEL_CTRL_D: // fallthrough
+ case SEL_PGUP: // fallthrough
+ case SEL_CTRL_U: // fallthrough
+ case SEL_HOME: // fallthrough
case SEL_END:
- switch (sel) {
- case SEL_NEXT:
- if (ndents)
- move_cursor((cur + 1) % ndents, 0);
- break;
- case SEL_PREV:
- if (ndents)
- move_cursor((cur + ndents - 1) % ndents, 0);
- break;
- case SEL_PGDN:
- onscreen = xlines - 4;
- move_cursor(curscroll + (onscreen - 1), 1);
- curscroll += onscreen - 1;
- break;
- case SEL_CTRL_D:
- onscreen = xlines - 4;
- move_cursor(curscroll + (onscreen - 1), 1);
- curscroll += onscreen >> 1;
- break;
- case SEL_PGUP: // fallthrough
- onscreen = xlines - 4;
- move_cursor(curscroll, 1);
- curscroll -= onscreen - 1;
- break;
- case SEL_CTRL_U:
- onscreen = xlines - 4;
- move_cursor(curscroll, 1);
- curscroll -= onscreen >> 1;
- break;
- case SEL_HOME:
- move_cursor(0, 1);
- break;
- default: /* case SEL_END: */
- move_cursor(ndents - 1, 1);
- break;
- }
+ handle_screen_move(sel);
break;
case SEL_CDHOME: // fallthrough
case SEL_CDBEGIN: // fallthrough