Rememeber last filter

This commit is contained in:
Arun Prakash Jana 2020-01-11 05:15:20 +05:30
parent c22bf87f3e
commit 0e203288b4
No known key found for this signature in database
GPG key ID: A75979F35C080412

View file

@ -1214,6 +1214,8 @@ static bool initcurses(mmask_t *oldmask)
g_ctx[i].color = 4; g_ctx[i].color = 4;
init_pair(i + 1, g_ctx[i].color, -1); init_pair(i + 1, g_ctx[i].color, -1);
g_ctx[i].c_fltr[REGEX_MAX - 1] = '\0';
} }
settimeout(); /* One second */ settimeout(); /* One second */
@ -1833,8 +1835,12 @@ static int (*filterfn)(const fltrexp_t *fltr, const char *fname) = &visible_str;
static void clearfilter() static void clearfilter()
{ {
if (g_ctx[cfg.curctx].c_fltr[1]) char *fltr = g_ctx[cfg.curctx].c_fltr;
g_ctx[cfg.curctx].c_fltr[1] = 0;
if (fltr[1]) {
fltr[REGEX_MAX - 1] = fltr[1];
fltr[1] = '\0';
}
} }
static int entrycmp(const void *va, const void *vb) static int entrycmp(const void *va, const void *vb)
@ -2080,10 +2086,11 @@ static int filterentries(char *path, char *lastname)
goto end; goto end;
} }
if (*ch == CONTROL('L')) if (*ch == CONTROL('L') && wln[1]) {
while (len > 1) ln[REGEX_MAX - 1] = ln[1];
wln[--len] = '\0'; wln[1] = '\0';
else len = 1;
} else
wln[--len] = '\0'; wln[--len] = '\0';
cur = 0; cur = 0;
@ -2098,6 +2105,18 @@ static int filterentries(char *path, char *lastname)
case KEY_MOUSE: // fallthrough case KEY_MOUSE: // fallthrough
case 27: /* Exit filter mode on Escape */ case 27: /* Exit filter mode on Escape */
goto end; goto end;
case KEY_UP: /* On the first Up, show previous filter */
if (len == 1 && ln[REGEX_MAX - 1]) {
ln[1] = ln[REGEX_MAX - 1];
ln[REGEX_MAX - 1] = '\0';
len = mbstowcs(wln, ln, REGEX_MAX);
if (matches(pln) != -1)
redraw(path);
printprompt(ln);
continue;
}
} }
if (r == OK) { if (r == OK) {
@ -2105,16 +2124,17 @@ static int filterentries(char *path, char *lastname)
if (*ch < ASCII_MAX && keyname(*ch)[0] == '^' && *ch != '^') if (*ch < ASCII_MAX && keyname(*ch)[0] == '^' && *ch != '^')
goto end; goto end;
if (len == 1) {
switch (*ch) { switch (*ch) {
case '=': // fallthrough /* Launch app */ case '=': // fallthrough /* Launch app */
case ']': // fallthorugh /*Prompt key */ case ']': // fallthorugh /*Prompt key */
case ';': // fallthrough /* Run plugin key */ case ';': // fallthrough /* Run plugin key */
case ',': // fallthrough /* Pin CWD */ case ',': // fallthrough /* Pin CWD */
case '?': /* Help and config key, '?' is an invalid regex */ case '?': /* Help and config key, '?' is an invalid regex */
if (len == 1)
goto end; goto end;
// fallthrough }
default: }
/* Reset cur in case it's a repeat search */ /* Reset cur in case it's a repeat search */
if (len == 1) if (len == 1)
cur = 0; cur = 0;
@ -2153,13 +2173,16 @@ static int filterentries(char *path, char *lastname)
*/ */
redraw(path); redraw(path);
printprompt(ln); printprompt(ln);
}
} else } else
goto end; break;
} }
end: end:
/* Save last working filter in-filter */
if (ln[1])
ln[REGEX_MAX - 1] = ln[1];
if (*ch != 27 && *ch != '\t' && *ch != KEY_UP && *ch != KEY_DOWN && *ch != CONTROL('T')) { if (*ch != 27 && *ch != '\t' && *ch != KEY_UP && *ch != KEY_DOWN && *ch != CONTROL('T')) {
g_ctx[cfg.curctx].c_fltr[0] = g_ctx[cfg.curctx].c_fltr[1] = '\0'; ln[0] = ln[1] = '\0';
move_cursor(cur, 0); move_cursor(cur, 0);
} else if (ndents) } else if (ndents)
xstrlcpy(lastname, dents[cur].name, NAME_MAX + 1); xstrlcpy(lastname, dents[cur].name, NAME_MAX + 1);