vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit e8bf38dae7c173a07e32d0cb2cd2511ce2abe202
parent 6dff861cc1d5f3b06d0bb3b1025367b7915f2c6e
Author: zsugabubus <zsugabubus@users.noreply.github.com>
Date:   Sun, 12 Jan 2020 15:57:48 +0100

vis: fix search wrapping bugs

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
\____/

Diffstat:
Mtext-motions.c | 3+--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git 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;