browser: allow backward/forward re-searches with Alt+Up/Alt+Down

Also bind 'N' to a backward re-search, while retaining 'n' for a
forward one,  This matches the functionality in the help viewer.
master
David Lawrence Ramsey 2017-08-14 15:58:25 -05:00 committed by Benno Schulenberg
parent 5fcda555ea
commit 633343de24
3 changed files with 31 additions and 18 deletions

View File

@ -171,11 +171,15 @@ char *do_browser(char *path)
say_there_is_no_help(); say_there_is_no_help();
#endif #endif
} else if (func == do_search) { } else if (func == do_search) {
/* Search for a filename. */
do_filesearch(); do_filesearch();
} else if (func == do_research) { } else if (func == do_research) {
/* Search for another filename. */ do_fileresearch(FALSE);
do_fileresearch(); #ifndef NANO_TINY
} else if (func == do_findprevious) {
do_fileresearch(TRUE);
} else if (func == do_findnext) {
do_fileresearch(FALSE);
#endif
} else if (func == do_left) { } else if (func == do_left) {
if (selected > 0) if (selected > 0)
selected--; selected--;
@ -488,6 +492,9 @@ functionptrtype parse_browser_input(int *kbinput)
case '/': case '/':
return do_search; return do_search;
case 'N': case 'N':
#ifndef NANO_TINY
return do_findprevious;
#endif
case 'n': case 'n':
return do_research; return do_research;
} }
@ -697,8 +704,9 @@ int filesearch_init(void)
return input; return input;
} }
/* Look for the given needle in the list of files. */ /* Look for the given needle in the list of files. If forwards is TRUE,
void findnextfile(const char *needle) * search forward in the list; otherwise, search backward. */
void findfile(const char *needle, bool forwards)
{ {
size_t looking_at = selected; size_t looking_at = selected;
/* The location in the file list of the filename we're looking at. */ /* The location in the file list of the filename we're looking at. */
@ -718,12 +726,16 @@ void findnextfile(const char *needle)
/* Step through each filename in the list until a match is found or /* Step through each filename in the list until a match is found or
* we've come back to the point where we started. */ * we've come back to the point where we started. */
while (TRUE) { while (TRUE) {
/* Move to the next filename in the list, or back to the first. */ if (forwards) {
if (looking_at < filelist_len - 1) if (looking_at++ == filelist_len - 1) {
looking_at++; looking_at = 0;
else { statusbar(_("Search Wrapped"));
looking_at = 0; }
statusbar(_("Search Wrapped")); } else {
if (looking_at-- == 0) {
looking_at = filelist_len - 1;
statusbar(_("Search Wrapped"));
}
} }
/* Get the bare filename, without the path. */ /* Get the bare filename, without the path. */
@ -770,16 +782,17 @@ void do_filesearch(void)
update_history(&search_history, answer); update_history(&search_history, answer);
#endif #endif
findnextfile(answer); findfile(answer, TRUE);
} }
/* Search again for the last given filename, without prompting. */ /* Search again without prompting for the last given search string,
void do_fileresearch(void) * either forwards or backwards. */
void do_fileresearch(bool forwards)
{ {
if (*last_search == '\0') if (*last_search == '\0')
statusbar(_("No current search pattern")); statusbar(_("No current search pattern"));
else else
findnextfile(last_search); findfile(last_search, forwards);
} }
/* Select the first file in the list. */ /* Select the first file in the list. */

View File

@ -1143,8 +1143,8 @@ void shortcut_init(void)
add_to_sclist(MMAIN, "M-\xE2\x86\x92", ALT_RIGHT, switch_to_next_buffer_void, 0); add_to_sclist(MMAIN, "M-\xE2\x86\x92", ALT_RIGHT, switch_to_next_buffer_void, 0);
#endif #endif
#ifndef NANO_TINY #ifndef NANO_TINY
add_to_sclist(MMAIN|MHELP, "M-\xE2\x86\x91", ALT_UP, do_findprevious, 0); add_to_sclist(MMAIN|MHELP|MBROWSER, "M-\xE2\x86\x91", ALT_UP, do_findprevious, 0);
add_to_sclist(MMAIN|MHELP, "M-\xE2\x86\x93", ALT_DOWN, do_findnext, 0); add_to_sclist(MMAIN|MHELP|MBROWSER, "M-\xE2\x86\x93", ALT_DOWN, do_findnext, 0);
#endif #endif
} else } else
#endif #endif

View File

@ -186,7 +186,7 @@ functionptrtype parse_browser_input(int *kbinput);
void browser_refresh(void); void browser_refresh(void);
void browser_select_dirname(const char *needle); void browser_select_dirname(const char *needle);
void do_filesearch(void); void do_filesearch(void);
void do_fileresearch(void); void do_fileresearch(bool forwards);
void do_first_file(void); void do_first_file(void);
void do_last_file(void); void do_last_file(void);
char *strip_last_component(const char *path); char *strip_last_component(const char *path);