Commit 9f1a44d9 authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

replacing: properly detect when we've rereached the starting position

Commit 8704dde8 mistakenly removed this part of code -- it is not dead,
it is just that it will only fire when the user answered No at some of
the replacement prompts.  So... when we've rereached the starting line,
a found occurrence is invalid when it is beyond the starting x (either
after or before it, dependending on the direction of search).

This fixes https://savannah.gnu.org/bugs/?47816.
No related merge requests found
Showing with 20 additions and 1 deletion
+20 -1
......@@ -266,6 +266,8 @@ int findnextstr(
/* When bigger than zero, show and wipe the "Searching..." message. */
filestruct *fileptr = openfile->current;
const char *rev_start = fileptr->data, *found = NULL;
size_t found_x;
/* The x coordinate of a found occurrence. */
time_t lastkbcheck = time(NULL);
/* rev_start might end up 1 character before the start or after the
......@@ -380,11 +382,28 @@ int findnextstr(
#endif
}
found_x = found - fileptr->data;
/* Ensure that the found occurrence is not beyond the starting x. */
if (search_last_line &&
#ifndef NANO_TINY
((!ISSET(BACKWARDS_SEARCH) && found_x > begin_x) ||
(ISSET(BACKWARDS_SEARCH) && found_x < begin_x))
#else
found_x > begin_x
#endif
) {
not_found_msg(needle);
disable_nodelay();
return 0;
}
disable_nodelay();
/* Set the current position to point at what we found. */
openfile->current = fileptr;
openfile->current_x = found - fileptr->data;
openfile->current_x = found_x;
openfile->current_y = fileptr->lineno - openfile->edittop->lineno;
/* When requested, pass back the length of the match. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment