mirror of
git://git.sv.gnu.org/nano.git
synced 2025-01-24 18:22:07 +03:00
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.
This commit is contained in:
parent
2a17527381
commit
e5440b390e
12
src/search.c
12
src/search.c
@ -254,10 +254,8 @@ int findnextstr(const char *needle, bool whole_word_only, int modus,
|
|||||||
if (!skipone)
|
if (!skipone)
|
||||||
found = strstrwrapper(line->data, needle, from);
|
found = strstrwrapper(line->data, needle, from);
|
||||||
|
|
||||||
/* Ignore the initial match at the starting position: continue
|
/* When starting a new search, skip the first character. */
|
||||||
* searching from the next character, or invalidate the match. */
|
if (skipone) {
|
||||||
if (skipone || (!whole_word_only && !came_full_circle &&
|
|
||||||
found == begin->data + begin_x)) {
|
|
||||||
skipone = FALSE;
|
skipone = FALSE;
|
||||||
if (ISSET(BACKWARDS_SEARCH) && from != line->data) {
|
if (ISSET(BACKWARDS_SEARCH) && from != line->data) {
|
||||||
from = line->data + move_mbleft(line->data, 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();
|
enable_waiting();
|
||||||
|
|
||||||
/* Ensure that the found occurrence is not beyond the starting x. */
|
/* 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)))
|
(ISSET(BACKWARDS_SEARCH) && found_x < begin_x)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -436,7 +434,7 @@ void go_looking(void)
|
|||||||
|
|
||||||
came_full_circle = FALSE;
|
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);
|
openfile->current, openfile->current_x);
|
||||||
|
|
||||||
/* If we found something, and we're back at the exact same spot
|
/* 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;
|
ssize_t numreplaced = -1;
|
||||||
size_t match_len;
|
size_t match_len;
|
||||||
bool replaceall = FALSE;
|
bool replaceall = FALSE;
|
||||||
bool skipone = FALSE;
|
bool skipone = ISSET(BACKWARDS_SEARCH);
|
||||||
int modus = REPLACING;
|
int modus = REPLACING;
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
filestruct *was_mark = openfile->mark;
|
filestruct *was_mark = openfile->mark;
|
||||||
|
Loading…
Reference in New Issue
Block a user