Skip to content

Commit

Permalink
Use / to toggle string and regex
Browse files Browse the repository at this point in the history
  • Loading branch information
jarun committed Jan 15, 2020
1 parent 73a2919 commit 0222b75
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
4 changes: 1 addition & 3 deletions nnn.1
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ Filters are strings to find matching entries in the current directory instantly
.Pp
To modify match criteria at runtime:
.br
- string to regex: press '\\' at empty filter prompt
.br
- regex to string: press '/' at empty filter prompt
- toggle between string and regex: press '/' at empty filter prompt
.br
- toggle case sensitivity: press ':' at empty filter prompt
.Pp
Expand Down
25 changes: 8 additions & 17 deletions src/nnn.c
Original file line number Diff line number Diff line change
Expand Up @@ -2072,7 +2072,7 @@ static void showfilterinfo(void)

i = getorderstr(info);

snprintf(info + i, REGEX_MAX - i - 1, " %s [keys /\\], %s [key :]",
snprintf(info + i, REGEX_MAX - i - 1, " %s [/], %s [:]",
(cfg.regex ? "regex" : "str"),
((fnstrstr == &strcasestr) ? "ic" : "noic"));
printinfoln(info);
Expand Down Expand Up @@ -2238,20 +2238,11 @@ static int filterentries(char *path, char *lastname)
continue;
}

/* string to regex */
if (*ch == RFILTER && ln[0] == FILTER) {
wln[0] = ln[0] = RFILTER;
cfg.regex = TRUE;
filterfn = &visible_re;
showfilter(ln);
continue;
}

/* regex to string */
if (*ch == FILTER && ln[0] == RFILTER) {
wln[0] = ln[0] = FILTER;
cfg.regex = FALSE;
filterfn = &visible_str;
/* toggle string or regex filter */
if (*ch == FILTER) {
wln[0] = ln[0] = (ln[0] == FILTER) ? RFILTER : FILTER;
cfg.regex ^= 1;
filterfn = (filterfn == &visible_str) ? &visible_re : &visible_str;
showfilter(ln);
continue;
}
Expand Down Expand Up @@ -4994,7 +4985,7 @@ static void browse(char *ipath, const char *session)
case SEL_MFLTR: // fallthrough
case SEL_TOGGLEDOT: // fallthrough
case SEL_DETAIL: // fallthrough
case SEL_ORDER:
case SEL_SORT:
switch (sel) {
case SEL_MFLTR:
cfg.filtermode ^= 1;
Expand All @@ -5020,7 +5011,7 @@ static void browse(char *ipath, const char *session)
cfg.showdetail ? (printptr = &printent_long) : (printptr = &printent);
cfg.blkorder = 0;
continue;
default: /* SEL_ORDER */
default: /* SEL_SORT */
r = get_input(messages[MSG_ORDER]);

if ((r == 'a' || r == 'd' || r == 'e' || r == 's' || r == 't')
Expand Down
6 changes: 3 additions & 3 deletions src/nnn.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ enum action {
SEL_STATS,
SEL_CHMODX,
SEL_ARCHIVE,
SEL_ORDER,
SEL_SORT,
SEL_REDRAW,
SEL_SEL,
SEL_SELMUL,
Expand Down Expand Up @@ -174,8 +174,8 @@ static struct key bindings[] = {
/* Create archive */
{ 'z', SEL_ARCHIVE },
/* Sort toggles */
{ 't', SEL_ORDER },
{ CONTROL('T'), SEL_ORDER },
{ 't', SEL_SORT },
{ CONTROL('T'), SEL_SORT },
/* Redraw window */
{ CONTROL('L'), SEL_REDRAW },
/* Select current file path */
Expand Down

0 comments on commit 0222b75

Please sign in to comment.