diff --git a/src/browser.c b/src/browser.c index 8b8d399f..cc7d7e10 100644 --- a/src/browser.c +++ b/src/browser.c @@ -604,11 +604,9 @@ void browser_select_dirname(const char *needle) } } -/* Prepare the prompt and ask the user what to search for. If forwards is - * TRUE, search forward in the list; otherwise, search backward. Return -2 - * for a blank answer, -1 for Cancel, 0 when we have a string, and a - * positive value when some function was run. */ -int filesearch_init(bool forwards) +/* Prepare the prompt and ask the user what to search for; then search for it. + * If forwards is TRUE, search forward in the list; otherwise, search backward. */ +void do_filesearch(bool forwards) { char *thedefault; int response; @@ -632,15 +630,22 @@ int filesearch_init(bool forwards) !forwards ? _(" [Backwards]") : "", thedefault); free(thedefault); - /* If only Enter was pressed but we have a previous string, it's okay. */ - if (response == -2 && *last_search != '\0') - return 0; - - /* Otherwise negative responses are a bailout. */ - if (response < 0) + /* If the user cancelled, or typed on a blank answer and + * nothing was searched for yet during this session, get out. */ + if (response == -1 || (response == -2 && *last_search == '\0')) { statusbar(_("Cancelled")); + return; + } - return response; + /* If the user typed an answer, remember it. */ + if (*answer != '\0') { + last_search = mallocstrcpy(last_search, answer); +#ifdef ENABLE_HISTORIES + update_history(&search_history, answer); +#endif + } + + findfile(last_search, forwards); } /* Look for the given needle in the list of files. If forwards is TRUE, @@ -702,25 +707,6 @@ void findfile(const char *needle, bool forwards) selected = looking_at; } -/* Search for a filename. If forwards is TRUE, search forward in the list; - * otherwise, search backward.*/ -void do_filesearch(bool forwards) -{ - /* If the user cancelled or jumped to first or last file, don't search. */ - if (filesearch_init(forwards) != 0) - return; - - /* If the user typed an answer, remember it. */ - if (*answer != '\0') { - last_search = mallocstrcpy(last_search, answer); -#ifdef ENABLE_HISTORIES - update_history(&search_history, answer); -#endif - } - - findfile(last_search, forwards); -} - /* Search again without prompting for the last given search string, * either forwards or backwards. */ void do_fileresearch(bool forwards) diff --git a/src/prototypes.h b/src/prototypes.h index 8cb25e76..d3593b22 100644 --- a/src/prototypes.h +++ b/src/prototypes.h @@ -193,6 +193,7 @@ void read_the_list(const char *path, DIR *dir); void browser_refresh(void); void browser_select_dirname(const char *needle); void do_filesearch(bool forwards); +void findfile(const char *needle, bool forwards); void do_fileresearch(bool forwards); char *strip_last_component(const char *path); #endif