commit e5440b390ee76f704773556ef38bcb853efd3e6f
parent 2a1752738108894f9210802ca3516aa27355840f
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Tue, 2 Jan 2018 21:20:32 +0100
replacing: don't skip the first character of a backwards-marked region
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.
Diffstat:
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git 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;