]> Sergey Matveev's repositories - nnn.git/commitdiff
Process keypress by probable frequency
authorArun Prakash Jana <engineerarun@gmail.com>
Tue, 12 Dec 2017 20:16:50 +0000 (01:46 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Tue, 12 Dec 2017 20:16:50 +0000 (01:46 +0530)
nnn.c
nnn.h

diff --git a/nnn.c b/nnn.c
index cccecc29e7c28e1e9aff808cb19ef978d8e52ea5..ecbdc796b94d2eca531115a9d2966d1076a1364f 100644 (file)
--- a/nnn.c
+++ b/nnn.c
@@ -2146,26 +2146,6 @@ nochange:
                sel = nextsel(&run, &env, &presel);
 
                switch (sel) {
-               case SEL_CDQUIT:
-               {
-                       char *tmpfile = "/tmp/nnn";
-
-                       tmp = getenv("NNN_TMPFILE");
-                       if (tmp)
-                               tmpfile = tmp;
-
-                       FILE *fp = fopen(tmpfile, "w");
-
-                       if (fp) {
-                               fprintf(fp, "cd \"%s\"", path);
-                               fclose(fp);
-                       }
-
-                       /* Fall through to exit */
-               } // fallthrough
-               case SEL_QUIT:
-                       dentfree(dents);
-                       return;
                case SEL_BACK:
                        /* There is no going back */
                        if (istopdir(path)) {
@@ -2264,24 +2244,6 @@ nochange:
                                printmsg("Unsupported file");
                                goto nochange;
                        }
-               case SEL_FLTR:
-                       presel = filterentries(path);
-                       xstrlcpy(fltr, ifilter, LINE_MAX);
-                       DPRINTF_S(fltr);
-                       /* Save current */
-                       if (ndents > 0)
-                               mkpath(path, dents[cur].name, oldpath, PATH_MAX);
-                       goto nochange;
-               case SEL_MFLTR:
-                       cfg.filtermode ^= 1;
-                       if (cfg.filtermode)
-                               presel = FILTER;
-                       else
-                               printmsg("navigate-as-you-type off");
-                       goto nochange;
-               case SEL_SEARCH:
-                       spawn(player, path, "search", NULL, F_NORMAL);
-                       break;
                case SEL_NEXT:
                        if (cur < ndents - 1)
                                ++cur;
@@ -2567,6 +2529,24 @@ nochange:
                        xstrlcpy(mark, path, PATH_MAX);
                        printmsg(mark);
                        goto nochange;
+               case SEL_FLTR:
+                       presel = filterentries(path);
+                       xstrlcpy(fltr, ifilter, LINE_MAX);
+                       DPRINTF_S(fltr);
+                       /* Save current */
+                       if (ndents > 0)
+                               mkpath(path, dents[cur].name, oldpath, PATH_MAX);
+                       goto nochange;
+               case SEL_MFLTR:
+                       cfg.filtermode ^= 1;
+                       if (cfg.filtermode)
+                               presel = FILTER;
+                       else
+                               printmsg("navigate-as-you-type off");
+                       goto nochange;
+               case SEL_SEARCH:
+                       spawn(player, path, "search", NULL, F_NORMAL);
+                       break;
                case SEL_TOGGLEDOT:
                        cfg.showhidden ^= 1;
                        initfilter(cfg.showhidden, &ifilter);
@@ -2785,6 +2765,26 @@ nochange:
                        run = xgetenv(env, run);
                        spawn(run, dents[cur].name, NULL, path, F_NORMAL);
                        break;
+               case SEL_CDQUIT:
+               {
+                       char *tmpfile = "/tmp/nnn";
+
+                       tmp = getenv("NNN_TMPFILE");
+                       if (tmp)
+                               tmpfile = tmp;
+
+                       FILE *fp = fopen(tmpfile, "w");
+
+                       if (fp) {
+                               fprintf(fp, "cd \"%s\"", path);
+                               fclose(fp);
+                       }
+
+                       /* Fall through to exit */
+               } // fallthrough
+               case SEL_QUIT:
+                       dentfree(dents);
+                       return;
                }
                /* Screensaver */
                if (idletimeout != 0 && idle == idletimeout) {
diff --git a/nnn.h b/nnn.h
index e904c84d89ef7d1f4cb6a05818c6a26d606fb0f5..6bf6477cdaff5e870e2f86738f8ffe433f98ea48 100644 (file)
--- a/nnn.h
+++ b/nnn.h
@@ -3,13 +3,8 @@
 
 /* Supported actions */
 enum action {
-       SEL_QUIT = 1,
-       SEL_CDQUIT,
-       SEL_BACK,
+       SEL_BACK = 1,
        SEL_GOIN,
-       SEL_FLTR,
-       SEL_MFLTR,
-       SEL_SEARCH,
        SEL_NEXT,
        SEL_PREV,
        SEL_PGDN,
@@ -23,6 +18,9 @@ enum action {
        SEL_CDBM,
        SEL_PIN,
        SEL_VISIT,
+       SEL_FLTR,
+       SEL_MFLTR,
+       SEL_SEARCH,
        SEL_TOGGLEDOT,
        SEL_DETAIL,
        SEL_STATS,
@@ -41,6 +39,8 @@ enum action {
        SEL_HELP,
        SEL_RUN,
        SEL_RUNARG,
+       SEL_CDQUIT,
+       SEL_QUIT,
 };
 
 /* Associate a pressed key to an action */
@@ -62,11 +62,6 @@ static struct assoc assocs[] = {
 };
 
 static struct key bindings[] = {
-       /* Quit */
-       { 'q',            SEL_QUIT,      "",     "" },
-       { CONTROL('Q'),   SEL_QUIT,      "",     "" },
-       /* Change dir on quit */
-       { 'Q',            SEL_CDQUIT,    "",     "" },
        /* Back */
        { KEY_BACKSPACE,  SEL_BACK,      "",     "" },
        { KEY_LEFT,       SEL_BACK,      "",     "" },
@@ -77,12 +72,6 @@ static struct key bindings[] = {
        { '\r',           SEL_GOIN,      "",     "" },
        { KEY_RIGHT,      SEL_GOIN,      "",     "" },
        { 'l',            SEL_GOIN,      "",     "" },
-       /* Filter */
-       { '/',            SEL_FLTR,      "",     "" },
-       /* Toggle filter mode */
-       { KEY_IC,         SEL_MFLTR,     "",     "" },
-       /* Desktop search */
-       { CONTROL('_'),   SEL_SEARCH,    "",     "" },
        /* Next */
        { 'j',            SEL_NEXT,      "",     "" },
        { KEY_DOWN,       SEL_NEXT,      "",     "" },
@@ -121,6 +110,12 @@ static struct key bindings[] = {
        { CONTROL('B'),   SEL_PIN,       "",     "" },
        /* Visit marked directory */
        { CONTROL('V'),   SEL_VISIT,     "",     "" },
+       /* Filter */
+       { '/',            SEL_FLTR,      "",     "" },
+       /* Toggle filter mode */
+       { KEY_IC,         SEL_MFLTR,     "",     "" },
+       /* Desktop search */
+       { CONTROL('_'),   SEL_SEARCH,    "",     "" },
        /* Toggle hide .dot files */
        { '.',            SEL_TOGGLEDOT, "",     "" },
        /* Detailed listing */
@@ -160,4 +155,9 @@ static struct key bindings[] = {
        /* Run command with argument */
        { 'e',            SEL_RUNARG,    "vi",   "EDITOR" },
        { 'p',            SEL_RUNARG,    "less", "PAGER" },
+       /* Change dir on quit */
+       { 'Q',            SEL_CDQUIT,    "",     "" },
+       /* Quit */
+       { 'q',            SEL_QUIT,      "",     "" },
+       { CONTROL('Q'),   SEL_QUIT,      "",     "" },
 };