commit 7a315071672ce3b6aa0114c2100558f9456463b2
parent 7f2031006a6ee4ea993c9c37dff4a0f678c06dcd
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date: Tue, 24 Jul 2018 17:11:25 -0500
bindings: make ^Q start a backward search also in the file browser
This makes the four search keystrokes (^W/^Q/M-W/M-Q) available in
all three areas of nano: editor, help viewer, and file browser.
Diffstat:
3 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/src/browser.c b/src/browser.c
@@ -166,9 +166,9 @@ char *do_browser(char *path)
say_there_is_no_help();
#endif
} else if (func == do_search_forward) {
- do_filesearch();
- } else if (func == do_research) {
- do_fileresearch(FORWARD);
+ do_filesearch(FORWARD);
+ } else if (func == do_search_backward) {
+ do_filesearch(BACKWARD);
} else if (func == do_findprevious) {
do_fileresearch(BACKWARD);
} else if (func == do_findnext) {
@@ -657,10 +657,11 @@ void browser_select_dirname(const char *needle)
}
}
-/* Prepare the prompt and ask the user what to search for. Return -2
+/* 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(void)
+int filesearch_init(bool forwards)
{
char *thedefault;
int response;
@@ -679,7 +680,8 @@ int filesearch_init(void)
/* Now ask what to search for. */
response = do_prompt(FALSE, FALSE, MWHEREISFILE, NULL, &search_history,
- browser_refresh, "%s%s", _("Search"), thedefault);
+ browser_refresh, "%s%s%s", _("Search"),
+ !forwards ? _(" [Backwards]") : "", thedefault);
free(thedefault);
/* If only Enter was pressed but we have a previous string, it's okay. */
@@ -752,11 +754,12 @@ void findfile(const char *needle, bool forwards)
selected = looking_at;
}
-/* Search for a filename. */
-void do_filesearch(void)
+/* 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() != 0)
+ if (filesearch_init(forwards) != 0)
return;
/* If answer is now "", copy last_search into answer. */
@@ -771,7 +774,7 @@ void do_filesearch(void)
update_history(&search_history, answer);
#endif
- findfile(answer, TRUE);
+ findfile(answer, forwards);
}
/* Search again without prompting for the last given search string,
diff --git a/src/global.c b/src/global.c
@@ -503,6 +503,7 @@ void shortcut_init(void)
{
const char *readfile_tag = N_("Read File");
const char *whereis_tag = N_("Where Is");
+ const char *wherewas_tag = N_("Where Was");
const char *replace_tag = N_("Replace");
const char *gotoline_tag = N_("Go To Line");
const char *prevline_tag = N_("Prev Line");
@@ -533,7 +534,8 @@ void shortcut_init(void)
const char *wherewas_gist =
N_("Search backward for a string or a regular expression");
#ifdef ENABLE_BROWSER
- const char *browserwhereis_gist = N_("Search for a string");
+ const char *browserwhereis_gist = N_("Search forward for a string");
+ const char *browserwherewas_gist = N_("Search backward for a string");
const char *browserrefresh_gist = N_("Refresh the file list");
#ifndef NANO_TINY
const char *browserlefthand_gist = N_("Go to lefthand column");
@@ -738,12 +740,6 @@ void shortcut_init(void)
replace_tag, WITHORSANS(replace_gist), TOGETHER, NOVIEW);
#ifdef ENABLE_BROWSER
- add_to_funcs(do_search_forward, MBROWSER,
- whereis_tag, WITHORSANS(browserwhereis_gist), TOGETHER, VIEW);
-
- add_to_funcs(do_research, MBROWSER,
- whereisnext_tag, WITHORSANS(whereisnext_gist), BLANKAFTER, VIEW);
-
add_to_funcs(goto_dir_void, MBROWSER,
N_("Go To Dir"), WITHORSANS(gotodir_gist), TOGETHER, VIEW);
@@ -841,7 +837,13 @@ void shortcut_init(void)
N_("Save"), WITHORSANS(savefile_gist), BLANKAFTER, NOVIEW);
#endif
- add_to_funcs(do_search_backward, MMAIN|MHELP|MBROWSER,
+#ifdef ENABLE_BROWSER
+ add_to_funcs(do_search_forward, MBROWSER,
+ whereis_tag, WITHORSANS(browserwhereis_gist), TOGETHER, VIEW);
+ add_to_funcs(do_search_backward, MBROWSER,
+ wherewas_tag, WITHORSANS(browserwherewas_gist), TOGETHER, VIEW);
+#endif
+ add_to_funcs(do_search_backward, MMAIN|MHELP,
/* TRANSLATORS: This starts a backward search. */
N_("Where Was"), WITHORSANS(wherewas_gist), TOGETHER, VIEW);
add_to_funcs(do_findprevious, MMAIN|MHELP|MBROWSER,
diff --git a/src/proto.h b/src/proto.h
@@ -190,7 +190,7 @@ void read_the_list(const char *path, DIR *dir);
functionptrtype parse_browser_input(int *kbinput);
void browser_refresh(void);
void browser_select_dirname(const char *needle);
-void do_filesearch(void);
+void do_filesearch(bool forwards);
void do_fileresearch(bool forwards);
void to_first_file(void);
void to_last_file(void);