Reporting "Cancelled" instead of "Not found" when the user aborts a replace

that is taking too long.  This fixes Savannah bug #47439.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5776 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Benno Schulenberg 2016-03-30 12:00:48 +00:00
parent b834ed3b28
commit 400e7ce13f
4 changed files with 30 additions and 17 deletions

View File

@ -1,3 +1,8 @@
2016-03-30 Benno Schulenberg <bensberg@justemail.net>
* src/search.c (do_replace_loop, go_looking, findnextstr): Report
"Cancelled" instead of "Not found" when the user aborts a replace
that is taking too long. This fixes Savannah bug #47439.
2016-03-29 Benno Schulenberg <bensberg@justemail.net> 2016-03-29 Benno Schulenberg <bensberg@justemail.net>
* src/nano.c (main), src/text.c (do_justify, do_verbatim_input), * src/nano.c (main), src/text.c (do_justify, do_verbatim_input),
src/winio.c (parse_escape_sequence): Place the cursor in the edit src/winio.c (parse_escape_sequence): Place the cursor in the edit

View File

@ -582,7 +582,7 @@ void regexp_cleanup(void);
void not_found_msg(const char *str); void not_found_msg(const char *str);
void search_replace_abort(void); void search_replace_abort(void);
int search_init(bool replacing, bool use_answer); int search_init(bool replacing, bool use_answer);
bool findnextstr( int findnextstr(
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
bool whole_word_only, bool whole_word_only,
#endif #endif

View File

@ -248,10 +248,10 @@ int search_init(bool replacing, bool use_answer)
} }
/* Look for needle, starting at (current, current_x). begin is the line /* Look for needle, starting at (current, current_x). begin is the line
* where we first started searching, at column begin_x. The return * where we first started searching, at column begin_x. Return 1 when we
* value specifies whether we found anything. If we did, set match_len * found something, 0 when nothing, and -2 on cancel. When match_len is
* to the length of the string we found if it isn't NULL. */ * not NULL, set it to the length of the found string, if any. */
bool findnextstr( int findnextstr(
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
bool whole_word_only, bool whole_word_only,
#endif #endif
@ -291,7 +291,7 @@ bool findnextstr(
if (input && func_from_key(&input) == do_cancel) { if (input && func_from_key(&input) == do_cancel) {
statusbar(_("Cancelled")); statusbar(_("Cancelled"));
return FALSE; return -2;
} }
if (++feedback > 0) if (++feedback > 0)
@ -310,7 +310,7 @@ bool findnextstr(
* again -- there is no need: we started at x = 0. */ * again -- there is no need: we started at x = 0. */
if (whole_word_only && search_last_line) { if (whole_word_only && search_last_line) {
disable_nodelay(); disable_nodelay();
return FALSE; return 0;
} }
#endif #endif
/* Remember the length of the potential match. */ /* Remember the length of the potential match. */
@ -343,7 +343,7 @@ bool findnextstr(
if (search_last_line) { if (search_last_line) {
not_found_msg(needle); not_found_msg(needle);
disable_nodelay(); disable_nodelay();
return FALSE; return 0;
} }
/* Move to the previous or next line in the file. */ /* Move to the previous or next line in the file. */
@ -402,7 +402,7 @@ bool findnextstr(
if (feedback > 0) if (feedback > 0)
blank_statusbar(); blank_statusbar();
return TRUE; return 1;
} }
/* Clear the flag indicating that a search reached the last line of the /* Clear the flag indicating that a search reached the last line of the
@ -492,7 +492,7 @@ void go_looking(void)
filestruct *was_current = openfile->current; filestruct *was_current = openfile->current;
size_t was_current_x = openfile->current_x; size_t was_current_x = openfile->current_x;
size_t was_pww = openfile->placewewant; size_t was_pww = openfile->placewewant;
bool didfind; int didfind;
findnextstr_wrap_reset(); findnextstr_wrap_reset();
didfind = findnextstr( didfind = findnextstr(
@ -503,7 +503,7 @@ void go_looking(void)
/* If we found something, and we're back at the exact same spot /* If we found something, and we're back at the exact same spot
* where we started searching, then this is the only occurrence. */ * where we started searching, then this is the only occurrence. */
if (didfind && openfile->current == was_current && if (didfind == 1 && openfile->current == was_current &&
openfile->current_x == was_current_x) openfile->current_x == was_current_x)
statusbar(_("This is the only occurrence")); statusbar(_("This is the only occurrence"));
@ -643,12 +643,20 @@ ssize_t do_replace_loop(
#endif /* !NANO_TINY */ #endif /* !NANO_TINY */
findnextstr_wrap_reset(); findnextstr_wrap_reset();
while (findnextstr( while (TRUE) {
int i = 0;
int result = findnextstr(
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
whole_word_only, whole_word_only,
#endif #endif
real_current, *real_current_x, needle, &match_len)) { real_current, *real_current_x, needle, &match_len);
int i = 0;
/* If nothing more was found, or the user aborted, stop looping. */
if (result < 1) {
if (result < 0)
numreplaced = -2; /* It's a Cancel instead of Not found. */
break;
}
#ifndef NANO_TINY #ifndef NANO_TINY
if (old_mark_set) { if (old_mark_set) {

View File

@ -2419,7 +2419,7 @@ bool do_int_spell_fix(const char *word)
/* Find the first whole occurrence of word. */ /* Find the first whole occurrence of word. */
findnextstr_wrap_reset(); findnextstr_wrap_reset();
while (findnextstr(TRUE, openfile->fileage, 0, word, &match_len)) { while (findnextstr(TRUE, openfile->fileage, 0, word, &match_len) == 1) {
if (is_whole_word(openfile->current_x, openfile->current->data, if (is_whole_word(openfile->current_x, openfile->current->data,
word)) { word)) {
size_t xpt = xplustabs(); size_t xpt = xplustabs();