]> Sergey Matveev's repositories - nnn.git/commitdiff
Use ^L to clear filter prompt
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 27 Oct 2018 20:22:07 +0000 (01:52 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 27 Oct 2018 20:22:07 +0000 (01:52 +0530)
README.md
nnn.1
nnn.c

index 5398c75b8865b318bd989eb78f00d3d27f089205..fb1cd33df901a19f0a5f8f5d1382aa8f1cc3cc01 100644 (file)
--- a/README.md
+++ b/README.md
@@ -265,10 +265,10 @@ Help & settings, file details, media info and archive listing are shown in the P
 
 Filters support regexes to instantly (search-as-you-type) list the matching entries in the current directory.
 
-There are 3 ways to reset a filter:
-- pressing <kbd>^L</kbd> (at the new/rename prompt <kbd>^L</kbd> followed by <kbd>Enter</kbd> discards all changes and exits prompt)
-- a search with no matches
-- an extra backspace at the filter prompt (like vi)
+Ways to exit filter prompt:
+- press <kbd>^L</kbd> to clear filter followed by <kbd>Bksp</kbd> (to clear the filter symbol, like vi)
+  - at other prompts <kbd>^L</kbd> followed by <kbd>Enter</kbd> discards all changes and exits prompt
+- run a search with no matches and press <kbd>Enter</kbd>
 
 Common use cases:
 - to list all matches starting with the filter expression, start the expression with a `^` (caret) symbol
diff --git a/nnn.1 b/nnn.1
index 7685c4c0de8cb958b2291b73d4920d75ea937433..a3e30575b9097c60180252a7a0d2a9cf32352bb1 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -188,14 +188,13 @@ instructions.
 Filters support regexes to instantly (search-as-you-type) list the matching
 entries in the current directory.
 .Pp
-There are 3 ways to reset a filter:
+Ways to exit filter prompt:
 .Pp
-(1) pressing \fI^L\fR (at the new/rename prompt \fI^L\fR followed by \fIEnter\fR
-discards all changes and exits prompt),
+(1) press \fI^L\fR to clear filter followed by \fIBksp\fR (to clear the filter symbol, like vi)
 .br
-(2) a search with no matches or
+  - at other prompts \fI^L\fR followed by \fIEnter\fR discards all changes and exits prompt
 .br
-(3) an extra backspace at the filter prompt (like vi).
+(2) run a search with no matches and press \fIEnter\fR
 .Pp
 Common use cases:
 .Pp
diff --git a/nnn.c b/nnn.c
index 52176370c618c9da714b6de02e79ee509db68dbc..dfb7b712d441b194e2e3e50c9995cbaeabfe10a3 100644 (file)
--- a/nnn.c
+++ b/nnn.c
@@ -1096,14 +1096,24 @@ static int filterentries(char *path)
        printprompt(ln);
 
        while ((r = get_wch(ch)) != ERR) {
-               if (*ch == 127 /* handle DEL */ || *ch == KEY_DC || *ch == KEY_BACKSPACE || *ch == '\b') {
-                       if (len == 1) {
+               switch (*ch) {
+               case KEY_DC: // fallthrough
+               case  KEY_BACKSPACE: // fallthrough
+               case '\b': // fallthrough
+               case CONTROL('L'): // fallthrough
+               case 127: /* handle DEL */
+                       if (len == 1 && *ch != CONTROL('L')) {
                                cur = oldcur;
                                *ch = CONTROL('L');
                                goto end;
                        }
 
-                       wln[--len] = '\0';
+                       if (*ch == CONTROL('L'))
+                               while (len > 1)
+                                       wln[--len] = '\0';
+                       else
+                               wln[--len] = '\0';
+
                        if (len == 1)
                                cur = oldcur;
 
@@ -1114,9 +1124,7 @@ static int filterentries(char *path)
 
                        printprompt(ln);
                        continue;
-               }
-
-               if (*ch == 27) { /* Exit filter mode on Escape */
+               case 27: /* Exit filter mode on Escape */
                        cur = oldcur;
                        *ch = CONTROL('L');
                        goto end;