aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--text-motions.c18
-rw-r--r--text-motions.h4
-rw-r--r--text-objects.c2
-rw-r--r--vis-motions.c2
-rw-r--r--vis.c3
5 files changed, 17 insertions, 12 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) {
diff --git a/text-motions.h b/text-motions.h
index 061ff30..b4fee28 100644
--- a/text-motions.h
+++ b/text-motions.h
@@ -117,9 +117,9 @@ size_t text_block_end(Text*, size_t pos);
size_t text_parenthesis_start(Text*, size_t pos);
size_t text_parenthesis_end(Text*, size_t pos);
/* search coresponding '(', ')', '{', '}', '[', ']', '>', '<', '"', ''' */
-size_t text_bracket_match(Text*, size_t pos);
+size_t text_bracket_match(Text*, size_t pos, const Filerange *limits);
/* same as above but explicitly specify symbols to match */
-size_t text_bracket_match_symbol(Text*, size_t pos, const char *symbols);
+size_t text_bracket_match_symbol(Text*, size_t pos, const char *symbols, const Filerange *limits);
/* search the given regex pattern in either forward or backward direction,
* starting from pos. does wrap around if no match was found. */
diff --git a/text-objects.c b/text-objects.c
index b39d13c..f4fcb4a 100644
--- a/text-objects.c
+++ b/text-objects.c
@@ -230,7 +230,7 @@ static Filerange text_object_bracket(Text *txt, size_t pos, char type) {
Iterator it = text_iterator_get(txt, pos);
if (open == close && text_iterator_byte_get(&it, &c) && (c == '"' || c == '`' || c == '\'')) {
- size_t match = text_bracket_match(txt, pos);
+ size_t match = text_bracket_match(txt, pos, NULL);
r.start = MIN(pos, match) + 1;
r.end = MAX(pos, match);
return r;
diff --git a/vis-motions.c b/vis-motions.c
index 4103eab..3702efa 100644
--- a/vis-motions.c
+++ b/vis-motions.c
@@ -181,7 +181,7 @@ static size_t window_nop(Vis *vis, Win *win, size_t pos) {
}
static size_t bracket_match(Text *txt, size_t pos) {
- size_t hit = text_bracket_match_symbol(txt, pos, "(){}[]<>'\"`");
+ size_t hit = text_bracket_match_symbol(txt, pos, "(){}[]<>'\"`", NULL);
if (hit != pos)
return hit;
char current;
diff --git a/vis.c b/vis.c
index 03b01ab..2c53f1a 100644
--- a/vis.c
+++ b/vis.c
@@ -371,7 +371,8 @@ static void window_draw_cursor_matching(Win *win, Selection *cur, CellStyle *sty
return;
Line *line_match; int col_match;
size_t pos = view_cursors_pos(cur);
- size_t pos_match = text_bracket_match_symbol(win->file->text, pos, "(){}[]\"'`");
+ Filerange limits = view_viewport_get(win->view);
+ size_t pos_match = text_bracket_match_symbol(win->file->text, pos, "(){}[]\"'`", &limits);
if (pos == pos_match)
return;
if (!view_coord_get(win->view, pos_match, &line_match, NULL, &col_match))