diff options
| author | Georgi Kirilov <in.the@repo> | 2018-10-02 19:10:58 +0300 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2020-01-26 16:28:36 +0100 |
| commit | 3a1023ee5022071b46f659a82290bb0b3da42137 (patch) | |
| tree | 307ae035f4c1e4e12008e8bed8bd456601f82106 /text-motions.c | |
| parent | b7013fa7e549162af478d58ffc1f5ed369f58408 (diff) | |
| download | vis-3a1023ee5022071b46f659a82290bb0b3da42137.tar.gz vis-3a1023ee5022071b46f659a82290bb0b3da42137.tar.xz | |
vis: don't search off screen when highlighting matches
Diffstat (limited to 'text-motions.c')
| -rw-r--r-- | text-motions.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/text-motions.c b/text-motions.c index b62dc23..0b4398d 100644 --- a/text-motions.c +++ b/text-motions.c @@ -524,11 +524,11 @@ size_t text_parenthesis_end(Text *txt, size_t pos) { return text_range_valid(&r) ? r.end : pos; } -size_t text_bracket_match(Text *txt, size_t pos) { - return text_bracket_match_symbol(txt, pos, NULL); +size_t text_bracket_match(Text *txt, size_t pos, const Filerange *limits) { + return text_bracket_match_symbol(txt, pos, NULL, limits); } -static size_t match_symbol(Text *txt, size_t pos, char search, int direction) { +static size_t match_symbol(Text *txt, size_t pos, char search, int direction, const Filerange *limits) { char c, current; int count = 1; bool instring = false; @@ -537,6 +537,8 @@ static size_t match_symbol(Text *txt, size_t pos, char search, int direction) { return pos; if (direction >= 0) { /* forward search */ while (text_iterator_byte_next(&it, &c)) { + if (limits && it.pos >= limits->end) + break; if (c != current && c == '"') instring = !instring; if (!instring) { @@ -548,6 +550,8 @@ static size_t match_symbol(Text *txt, size_t pos, char search, int direction) { } } else { /* backwards */ while (text_iterator_byte_prev(&it, &c)) { + if (limits && it.pos < limits->start) + break; if (c != current && c == '"') instring = !instring; if (!instring) { @@ -562,7 +566,7 @@ static size_t match_symbol(Text *txt, size_t pos, char search, int direction) { return pos; /* no match found */ } -size_t text_bracket_match_symbol(Text *txt, size_t pos, const char *symbols) { +size_t text_bracket_match_symbol(Text *txt, size_t pos, const char *symbols, const Filerange *limits) { int direction; char search, current, c; Iterator it = text_iterator_get(txt, pos); @@ -584,8 +588,8 @@ size_t text_bracket_match_symbol(Text *txt, size_t pos, const char *symbols) { case '\'': { /* prefer matches on the same line */ - size_t fw = match_symbol(txt, pos, current, +1); - size_t bw = match_symbol(txt, pos, current, -1); + size_t fw = match_symbol(txt, pos, current, +1, limits); + size_t bw = match_symbol(txt, pos, current, -1, limits); if (fw == pos) return bw; if (bw == pos) @@ -611,7 +615,7 @@ size_t text_bracket_match_symbol(Text *txt, size_t pos, const char *symbols) { return pos; } - return match_symbol(txt, pos, search, direction); + return match_symbol(txt, pos, search, direction, limits); } size_t text_search_forward(Text *txt, size_t pos, Regex *regex) { |
