From a6740ba3fd784333adb585b9402ff74e3432d7d8 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sat, 19 Mar 2016 16:19:44 +0000 Subject: [PATCH] Storing always the last-typed string, also when it's an invalid regex. This fixes Savannah bug #47440. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5742 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 4 ++++ src/search.c | 32 +++++++++----------------------- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index fee803ae..d886a7e9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-03-19 Benno Schulenberg + * src/search.c (search_init): Always remember the last typed string, + also when it's an invalid regex. This fixes Savannah bug #47440. + 2016-03-17 Benno Schulenberg * src/search.c (do_research): Use the Search key bindings also during a Re-search, to enable cancelling. This fixes Savannah bug #47159. diff --git a/src/search.c b/src/search.c index 2855d866..6ceb9af0 100644 --- a/src/search.c +++ b/src/search.c @@ -206,10 +206,14 @@ int search_init(bool replacing, bool use_answer) if (i == -2 || i == 0 ) { #ifdef HAVE_REGEX_H - /* Use last_search if answer is an empty string, or - * answer if it isn't. */ - if (ISSET(USE_REGEXP) && !regexp_init((i == -2) ? - last_search : answer)) + /* If an answer was given, remember it. */ + if (*answer != '\0') { + last_search = mallocstrcpy(last_search, answer); +#ifndef DISABLE_HISTORIES + update_history(&search_history, answer); +#endif + } + if (ISSET(USE_REGEXP) && !regexp_init(last_search)) return -1; #endif ; @@ -431,18 +435,9 @@ void do_search(void) if (i != 0) return; - /* If answer is now "", copy last_search into answer. */ + /* If answer is empty, use what was last searched for. */ if (*answer == '\0') answer = mallocstrcpy(answer, last_search); - else - last_search = mallocstrcpy(last_search, answer); - -#ifndef DISABLE_HISTORIES - /* If answer is not "", add this search string to the search history - * list. */ - if (answer[0] != '\0') - update_history(&search_history, answer); -#endif findnextstr_wrap_reset(); didfind = findnextstr( @@ -850,15 +845,6 @@ void do_replace(void) if (i != 0) return; - /* If answer is not "", add answer to the search history list and - * copy answer into last_search. */ - if (answer[0] != '\0') { -#ifndef DISABLE_HISTORIES - update_history(&search_history, answer); -#endif - last_search = mallocstrcpy(last_search, answer); - } - last_replace = mallocstrcpy(last_replace, ""); i = do_prompt(FALSE,