]> Sergey Matveev's repositories - nnn.git/commitdiff
Refactor screen move
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 19 Oct 2019 03:31:23 +0000 (09:01 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 19 Oct 2019 03:40:52 +0000 (09:10 +0530)
README.md
src/nnn.c

index 89a928219f46774358c592f82ad9c3747d917dea..f44717c5746bde8d2e95d5fe927e45e2f7d72758 100644 (file)
--- a/README.md
+++ b/README.md
@@ -209,11 +209,10 @@ The list below is from the **dev branch**. Press <kbd>?</kbd> in `nnn` to see th
  FILES
            ^O  Open with...      n  Create new/link
             D  File detail   ^R F2  Rename/duplicate
-         ⎵ ^J  Select entry      r  Batch rename
+       ⎵ ^J/a  Select entry/all  r  Batch rename
          m ^K  Sel range, clear  M  List selection
-            a  Select all        K  Edit selection
-            P  Copy selection    w  Copy selection as
-            V  Move selection    W  Move selection as
+            P  Copy selection    K  Edit selection
+            V  Move selection    w  Copy/move sel as
             X  Del selection    ^X  Del entry
             f  Create archive    T  Mount archive
            ^F  Extract archive   F  List archive
index 146765e667934513e39c82f2381268cd3a903702..cfee8dd0608924a15fea040e476953bc73e0dc4c 100644 (file)
--- 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