nano-devel
[Top][All Lists]
Advanced

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

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


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH v2] replacing: don't skip the first character of a backwards-marked region
Date: Sat, 6 Jan 2018 10:57:57 +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.
---
 src/search.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/search.c b/src/search.c
index 88cd1ffe..ede69d6a 100644
--- a/src/search.c
+++ b/src/search.c
@@ -254,10 +254,10 @@ 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)) {
+               /* Skip the first character when requested OR when we're back 
at the
+                * beginning during a forward search. */
+               if (skipone || (came_full_circle && found == begin->data + 
begin_x &&
+                                                                               
        !ISSET(BACKWARDS_SEARCH))) {
                        skipone = FALSE;
                        if (ISSET(BACKWARDS_SEARCH) && from != line->data) {
                                from = line->data + move_mbleft(line->data, 
from - line->data);
@@ -436,7 +436,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 +546,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]