From 9bf486fe5dc286482c5578575cd16c7c47734d7b Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Tue, 26 Oct 2004 20:58:30 +0000 Subject: [PATCH] in do_replace_loop(), add new parameter canceled, set to TRUE if we canceled at the prompt and FALSE otherwise; use it to make sure that canceling works properly in all cases when using the internal spell checker git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2028 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 5 +++++ src/nano.c | 13 +++++++------ src/proto.h | 2 +- src/search.c | 16 ++++++++++++---- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3e4667de..e5f8a467 100644 --- a/ChangeLog +++ b/ChangeLog @@ -155,6 +155,9 @@ CVS code - the spell checker will sometimes only correct the misspelled word instances that appear before the cursor position and then stop. (Rocco) + - Use do_replace_loop()'s canceled parameter in order to ensure + that the spell checking stops if we canceled at the replace + prompt. (DLR) do_alt_speller() - Call terminal_init() unconditionally after running the alternate spell checker, so that the terminal state is @@ -221,6 +224,8 @@ CVS code - replacing only marked text when the mark is on. (DLR, suggested by Joseph Birthisel) - Return ssize_t instead of int. (DLR) + - Add new parameter canceled, set to TRUE if we canceled at the + prompt and FALSE otherwise. (DLR) - utils.c: regexp_bol_or_eol() - Don't assume any longer that string will be found if diff --git a/src/nano.c b/src/nano.c index c38d59e4..3fb17faa 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1424,7 +1424,7 @@ bool do_int_spell_fix(const char *word) filestruct *edittop_save = edittop; filestruct *current_save = current; /* Save where we are. */ - bool accepted = TRUE; + bool canceled = FALSE; /* The return value. */ bool case_sens_set = ISSET(CASE_SENSITIVE); #ifndef NANO_SMALL @@ -1477,17 +1477,18 @@ bool do_int_spell_fix(const char *word) do_replace_highlight(TRUE, word); /* Allow all instances of the word to be corrected. */ - accepted = (statusq(FALSE, spell_list, word, + canceled = (statusq(FALSE, spell_list, word, #ifndef NANO_SMALL NULL, #endif - _("Edit a replacement")) != -1); + _("Edit a replacement")) == -1); do_replace_highlight(FALSE, word); - if (accepted && strcmp(word, answer) != 0) { + if (!canceled && strcmp(word, answer) != 0) { current_x--; - do_replace_loop(word, current, ¤t_x, TRUE); + do_replace_loop(word, current, ¤t_x, TRUE, + &canceled); } break; @@ -1526,7 +1527,7 @@ bool do_int_spell_fix(const char *word) SET(MARK_ISSET); #endif - return accepted; + return !canceled; } /* Integrated spell checking using 'spell' program. Return value: NULL diff --git a/src/proto.h b/src/proto.h index 0726ca0b..3f2a1d87 100644 --- a/src/proto.h +++ b/src/proto.h @@ -416,7 +416,7 @@ int replace_regexp(char *string, bool create_flag); #endif char *replace_line(const char *needle); ssize_t do_replace_loop(const char *needle, filestruct *real_current, - size_t *real_current_x, bool wholewords); + size_t *real_current_x, bool wholewords, bool *canceled); void do_replace(void); void do_gotoline(int line, bool save_pos); void do_gotoline_void(void); diff --git a/src/search.c b/src/search.c index 43ef06e3..1abf9386 100644 --- a/src/search.c +++ b/src/search.c @@ -652,9 +652,10 @@ char *replace_line(const char *needle) * is replaced by a shorter word. * * needle is the string to seek. We replace it with answer. Return -1 - * if needle isn't found, else the number of replacements performed. */ + * if needle isn't found, else the number of replacements performed. If + * canceled isn't NULL, set it to TRUE if we canceled. */ ssize_t do_replace_loop(const char *needle, filestruct *real_current, - size_t *real_current_x, bool wholewords) + size_t *real_current_x, bool wholewords, bool *canceled) { ssize_t numreplaced = -1; size_t match_len; @@ -687,6 +688,9 @@ ssize_t do_replace_loop(const char *needle, filestruct *real_current, } #endif + if (canceled != NULL) + *canceled = FALSE; + while (findnextstr(TRUE, wholewords, #ifdef HAVE_REGEX_H /* We should find a bol and/or eol regex only once per line. If @@ -772,8 +776,11 @@ ssize_t do_replace_loop(const char *needle, filestruct *real_current, free(exp_word); curs_set(1); - if (i == -1) /* We canceled the replace. */ + if (i == -1) { /* We canceled the replace. */ + if (canceled != NULL) + *canceled = TRUE; break; + } } #ifdef HAVE_REGEX_H @@ -937,7 +944,8 @@ void do_replace(void) beginx = current_x; pww_save = placewewant; - numreplaced = do_replace_loop(last_search, begin, &beginx, FALSE); + numreplaced = do_replace_loop(last_search, begin, &beginx, FALSE, + NULL); /* Restore where we were. */ edittop = edittop_save; -- 2.39.5