Use ^L to clear filter prompt

This commit is contained in:
Arun Prakash Jana 2018-10-28 01:52:07 +05:30
parent 80e5cdfe8d
commit c820e0c9f9
No known key found for this signature in database
GPG key ID: A75979F35C080412
3 changed files with 22 additions and 15 deletions

View file

@ -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. 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: Ways to exit filter prompt:
- pressing <kbd>^L</kbd> (at the new/rename prompt <kbd>^L</kbd> followed by <kbd>Enter</kbd> discards all changes and exits prompt) - press <kbd>^L</kbd> to clear filter followed by <kbd>Bksp</kbd> (to clear the filter symbol, like vi)
- a search with no matches - at other prompts <kbd>^L</kbd> followed by <kbd>Enter</kbd> discards all changes and exits prompt
- an extra backspace at the filter prompt (like vi) - run a search with no matches and press <kbd>Enter</kbd>
Common use cases: Common use cases:
- to list all matches starting with the filter expression, start the expression with a `^` (caret) symbol - to list all matches starting with the filter expression, start the expression with a `^` (caret) symbol

9
nnn.1
View file

@ -188,14 +188,13 @@ instructions.
Filters support regexes to instantly (search-as-you-type) list the matching Filters support regexes to instantly (search-as-you-type) list the matching
entries in the current directory. entries in the current directory.
.Pp .Pp
There are 3 ways to reset a filter: Ways to exit filter prompt:
.Pp .Pp
(1) pressing \fI^L\fR (at the new/rename prompt \fI^L\fR followed by \fIEnter\fR (1) press \fI^L\fR to clear filter followed by \fIBksp\fR (to clear the filter symbol, like vi)
discards all changes and exits prompt),
.br .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 .br
(3) an extra backspace at the filter prompt (like vi). (2) run a search with no matches and press \fIEnter\fR
.Pp .Pp
Common use cases: Common use cases:
.Pp .Pp

18
nnn.c
View file

@ -1096,14 +1096,24 @@ static int filterentries(char *path)
printprompt(ln); printprompt(ln);
while ((r = get_wch(ch)) != ERR) { while ((r = get_wch(ch)) != ERR) {
if (*ch == 127 /* handle DEL */ || *ch == KEY_DC || *ch == KEY_BACKSPACE || *ch == '\b') { switch (*ch) {
if (len == 1) { 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; cur = oldcur;
*ch = CONTROL('L'); *ch = CONTROL('L');
goto end; goto end;
} }
if (*ch == CONTROL('L'))
while (len > 1)
wln[--len] = '\0'; wln[--len] = '\0';
else
wln[--len] = '\0';
if (len == 1) if (len == 1)
cur = oldcur; cur = oldcur;
@ -1114,9 +1124,7 @@ static int filterentries(char *path)
printprompt(ln); printprompt(ln);
continue; continue;
} case 27: /* Exit filter mode on Escape */
if (*ch == 27) { /* Exit filter mode on Escape */
cur = oldcur; cur = oldcur;
*ch = CONTROL('L'); *ch = CONTROL('L');
goto end; goto end;