nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH v3] replacing: don't skip the first character of a b


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH v3] replacing: don't skip the first character of a backwards-marked region
Date: Sat, 6 Jan 2018 17:31:17 +0100

Also, when replacing forwards, do not first skip the occurrence at the
cursor and then replace it at the end of the cycle, but begin with it,
as one would expect.

This fixes https://savannah.gnu.org/bugs/?52789
and fixes https://savannah.gnu.org/bugs/?52791.

  [ Should do the same as v2, but with fewer conditions. ]

---
 src/search.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/src/search.c b/src/search.c
index 88cd1ffe..02a529fc 100644
--- a/src/search.c
+++ b/src/search.c
@@ -254,10 +254,8 @@ int findnextstr(const char *needle, bool whole_word_only, 
int modus,
                if (!skipone)
                        found = strstrwrapper(line->data, needle, from);
 
-               /* Ignore the initial match at the starting position: continue
-                * searching from the next character, or invalidate the match. 
*/
-               if (skipone || (!whole_word_only && !came_full_circle &&
-                                                               found == 
begin->data + begin_x)) {
+               /* When starting a new search, skip the first character. */
+               if (skipone) {
                        skipone = FALSE;
                        if (ISSET(BACKWARDS_SEARCH) && from != line->data) {
                                from = line->data + move_mbleft(line->data, 
from - line->data);
@@ -333,7 +331,7 @@ int findnextstr(const char *needle, bool whole_word_only, 
int modus,
        enable_waiting();
 
        /* Ensure that the found occurrence is not beyond the starting x. */
-       if (came_full_circle && ((!ISSET(BACKWARDS_SEARCH) && found_x > 
begin_x) ||
+       if (came_full_circle && ((!ISSET(BACKWARDS_SEARCH) && found_x >= 
begin_x) ||
                                                (ISSET(BACKWARDS_SEARCH) && 
found_x < begin_x)))
                return 0;
 
@@ -436,7 +434,7 @@ void go_looking(void)
 
        came_full_circle = FALSE;
 
-       didfind = findnextstr(last_search, FALSE, JUSTFIND, NULL, FALSE,
+       didfind = findnextstr(last_search, FALSE, JUSTFIND, NULL, TRUE,
                                                                
openfile->current, openfile->current_x);
 
        /* If we found something, and we're back at the exact same spot
@@ -546,7 +544,7 @@ ssize_t do_replace_loop(const char *needle, bool 
whole_word_only,
        ssize_t numreplaced = -1;
        size_t match_len;
        bool replaceall = FALSE;
-       bool skipone = FALSE;
+       bool skipone = ISSET(BACKWARDS_SEARCH);
        int modus = REPLACING;
 #ifndef NANO_TINY
        filestruct *was_mark = openfile->mark;
-- 
2.14.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]