Bladeren bron

Code refactor

master
Arun Prakash Jana 5 jaren geleden
bovenliggende
commit
9b45b05746
Geen bekende sleutel gevonden voor deze handtekening in de database GPG sleutel-ID: A75979F35C080412
1 gewijzigde bestanden met toevoegingen van 73 en 83 verwijderingen
  1. +73
    -83
      src/nnn.c

+ 73
- 83
src/nnn.c Bestand weergeven

@@ -2150,41 +2150,31 @@ static int filterentries(char *path, char *lastname)
case KEY_DC: // fallthrough case KEY_DC: // fallthrough
case KEY_BACKSPACE: // fallthrough case KEY_BACKSPACE: // fallthrough
case '\b': // fallthrough case '\b': // fallthrough
case CONTROL('L'): // fallthrough
case 127: /* handle DEL */ case 127: /* handle DEL */
if (len == 1 && *ch != CONTROL('L')) { if (len != 1) {
wln[--len] = '\0';
wcstombs(ln, wln, REGEX_MAX);
ndents = total;
} else
*ch = CONTROL('L'); *ch = CONTROL('L');
goto end; // fallthrough
} case CONTROL('L'):

if (*ch == CONTROL('L')) { if (*ch == CONTROL('L')) {
if (wln[1]) { if (wln[1]) {
ln[REGEX_MAX - 1] = ln[1]; ln[REGEX_MAX - 1] = ln[1];
wln[1] = '\0'; ln[1] = wln[1] = '\0';
len = 1; len = 1;
ndents = total;
} else if (ln[REGEX_MAX - 1]) { /* Show the previous filter */ } else if (ln[REGEX_MAX - 1]) { /* Show the previous filter */
ln[1] = ln[REGEX_MAX - 1]; ln[1] = ln[REGEX_MAX - 1];
ln[REGEX_MAX - 1] = '\0'; ln[REGEX_MAX - 1] = '\0';
len = mbstowcs(wln, ln, REGEX_MAX); len = mbstowcs(wln, ln, REGEX_MAX);
/*
* Go to the top, we don't know if the
* hovered file will match the filter
*/
cur = 0;

if (matches(pln) != -1)
redraw(path);

showfilter(ln);
continue;
} }
} else }
wln[--len] = '\0';


/* Go to the top, we don't know if the hovered file will match the filter */
cur = 0; cur = 0;


wcstombs(ln, wln, REGEX_MAX);
ndents = total;
if (matches(pln) != -1) if (matches(pln) != -1)
redraw(path); redraw(path);


@@ -2195,79 +2185,79 @@ static int filterentries(char *path, char *lastname)
goto end; goto end;
} }


if (r == OK) { if (r != OK) /* Handle Fn keys in main loop */
/* Handle all control chars in main loop */ break;
if (*ch < ASCII_MAX && keyname(*ch)[0] == '^' && *ch != '^')
goto end;

if (len == 1) {
switch (*ch) {
case '=': // fallthrough /* Launch app */
case ']': // fallthorugh /*Prompt key */
case ';': // fallthrough /* Run plugin key */
case ',': // fallthrough /* Pin CWD */
case '?': /* Help and config key, '?' is an invalid regex */
goto end;
}


/* Toggle case-sensitivity */ /* Handle all control chars in main loop */
if (*ch == CASE) { if (*ch < ASCII_MAX && keyname(*ch)[0] == '^' && *ch != '^')
fnstrstr = (fnstrstr == &strcasestr) ? &strstr : &strcasestr; goto end;
regflags ^= REG_ICASE;
showfilter(ln);
continue;
}


/* toggle string or regex filter */ if (len == 1) {
if (*ch == FILTER) { switch (*ch) {
wln[0] = ln[0] = (ln[0] == FILTER) ? RFILTER : FILTER; case '=': // fallthrough /* Launch app */
cfg.regex ^= 1; case ']': // fallthorugh /*Prompt key */
filterfn = (filterfn == &visible_str) ? &visible_re : &visible_str; case ';': // fallthrough /* Run plugin key */
showfilter(ln); case ',': // fallthrough /* Pin CWD */
continue; case '?': /* Help and config key, '?' is an invalid regex */
} goto end;
} }


/* Reset cur in case it's a repeat search */ /* Toggle case-sensitivity */
if (len == 1) if (*ch == CASE) {
cur = 0; fnstrstr = (fnstrstr == &strcasestr) ? &strstr : &strcasestr;

regflags ^= REG_ICASE;
if (len == REGEX_MAX - 1)
break;

wln[len] = (wchar_t)*ch;
wln[++len] = '\0';
wcstombs(ln, wln, REGEX_MAX);

/* Forward-filtering optimization:
* - new matches can only be a subset of current matches.
*/
/* ndents = total; */

if (matches(pln) == -1) {
showfilter(ln); showfilter(ln);
continue; continue;
} }


/* If the only match is a dir, auto-select and cd into it */ /* toggle string or regex filter */
if (ndents == 1 && cfg.filtermode if (*ch == FILTER) {
&& cfg.autoselect && (dents[0].flags & DIR_OR_LINK_TO_DIR)) { wln[0] = ln[0] = (ln[0] == FILTER) ? RFILTER : FILTER;
*ch = KEY_ENTER; cfg.regex ^= 1;
cur = 0; filterfn = (filterfn == &visible_str) ? &visible_re : &visible_str;
goto end; showfilter(ln);
continue;
} }
}


/* /* Reset cur in case it's a repeat search */
* redraw() should be above the auto-select optimization, for if (len == 1)
* the case where there's an issue with dir auto-select, say, cur = 0;
* due to a permission problem. The transition is _jumpy_ in if (len == REGEX_MAX - 1)
* case of such an error. However, we optimize for successful
* cases where the dir has permissions. This skips a redraw().
*/
redraw(path);
showfilter(ln);
} else
break; break;

wln[len] = (wchar_t)*ch;
wln[++len] = '\0';
wcstombs(ln, wln, REGEX_MAX);

/* Forward-filtering optimization:
* - new matches can only be a subset of current matches.
*/
/* ndents = total; */

if (matches(pln) == -1) {
showfilter(ln);
continue;
}

/* If the only match is a dir, auto-select and cd into it */
if (ndents == 1 && cfg.filtermode
&& cfg.autoselect && (dents[0].flags & DIR_OR_LINK_TO_DIR)) {
*ch = KEY_ENTER;
cur = 0;
goto end;
}

/*
* redraw() should be above the auto-select optimization, for
* the case where there's an issue with dir auto-select, say,
* due to a permission problem. The transition is _jumpy_ in
* case of such an error. However, we optimize for successful
* cases where the dir has permissions. This skips a redraw().
*/
redraw(path);
showfilter(ln);
} }
end: end:
clearinfoln(); clearinfoln();


||||||
x
 
000:0
Laden…
Annuleren
Opslaan