From c9831b1120e7c29419183c5fde8cf1bf4e69d5bd Mon Sep 17 00:00:00 2001 From: zsugabubus Date: Sun, 12 Jan 2020 15:57:48 +0100 Subject: vis: fix search wrapping bugs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1) “$” matches in the middle of the text. visvis ^ - standing here \/ - at first we search forward-\ \_/ - wrap, if nothing found <---/ After wrapping, in the second range “$” will treat end of the range as EOL so “/vis$” will wisely match and moves cursor to the first column. 2) No match after wrapping. vissssss ^^ - standing here or here \\____/ - search this before wrapping ---\ V - search range after wrapping <--/ “/vis” will *not* match (after wrapping), because it crosses ranges. --- So the real solution would be that instead of the end position, the start position of the possible match should be limited because a match can cross the search ranges. To keep things simple, simply search two whole text after wrapping. visvis \____/ --- text-motions.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/text-motions.c b/text-motions.c index 689bb1f..533d896 100644 --- a/text-motions.c +++ b/text-motions.c @@ -622,8 +622,7 @@ size_t text_search_forward(Text *txt, size_t pos, Regex *regex) { if (!found) { start = 0; - end = pos; - found = !text_search_range_forward(txt, start, end, regex, 1, match, 0); + found = !text_search_range_forward(txt, start, end - start, regex, 1, match, 0); } return found ? match[0].start : pos; -- cgit v1.2.3