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.
master
Benno Schulenberg 2018-01-02 21:20:32 +01:00
parent 2a17527381
commit e5440b390e
1 changed files with 5 additions and 7 deletions

View File

@ -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;