From 00c1105c1b7bc6572d24f2943315fe4be94211ba Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 14 Jan 2018 22:17:47 +0100 Subject: [PATCH] search: suppress the occurrence at the cursor only when replacing When we're just searching, we do want to report the occurrence at the cursor (after coming full circle) as a match, so that we can mention that this is the only occurrence. When replacing, we do not want to replace this match twice. This fixes https://savannah.gnu.org/bugs/?52888. --- src/search.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/search.c b/src/search.c index 39e43061..b223ffc8 100644 --- a/src/search.c +++ b/src/search.c @@ -328,7 +328,8 @@ 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 || + (modus == REPLACING && found_x == begin_x))) || (ISSET(BACKWARDS_SEARCH) && found_x < begin_x))) return 0;