diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2014-08-28 16:55:48 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2014-08-28 16:55:48 +0200 |
| commit | ac4570c5534fbc9499d15eb58d97fbb2048e5fc6 (patch) | |
| tree | 9d9cac22f19882c6fcd7200961fc97e0bdd84a29 /text-motions.c | |
| parent | 63304991187eeefb656fdb4ba6fc04d21601ebae (diff) | |
| download | vis-ac4570c5534fbc9499d15eb58d97fbb2048e5fc6.tar.gz vis-ac4570c5534fbc9499d15eb58d97fbb2048e5fc6.tar.xz | |
motion: improve matching of single and double quotes
Diffstat (limited to 'text-motions.c')
| -rw-r--r-- | text-motions.c | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/text-motions.c b/text-motions.c index e57738c..090e727 100644 --- a/text-motions.c +++ b/text-motions.c @@ -1,4 +1,5 @@ #include <ctype.h> +#include <string.h> #include "text-motions.h" #include "util.h" @@ -241,31 +242,38 @@ size_t text_bracket_match(Text *txt, size_t pos) { case ']': search = '['; direction = -1; break; case '<': search = '>'; direction = 1; break; case '>': search = '<'; direction = -1; break; - // TODO: heuristic basic on neighbouring chars shared with text-object - case '"': search = '"'; direction = 1; break; - case '\'': search = '\''; direction = 1; break; + case '"': + case '\'': { + char special[] = " \n)}]>.,"; + search = current; + direction = 1; + if (text_iterator_byte_next(&it, &c)) { + /* if a single or double quote is followed by + * a special character, search backwards */ + if (memchr(special, c, sizeof(special))) + direction = -1; + text_iterator_byte_prev(&it, NULL); + } + break; + } default: return pos; } if (direction >= 0) { /* forward search */ while (text_iterator_byte_next(&it, &c)) { - if (c == search && --count == 0) { - pos = it.pos; - break; - } else if (c == current) { + if (c == search && --count == 0) + return it.pos; + else if (c == current) count++; - } } } else { /* backwards */ while (text_iterator_byte_prev(&it, &c)) { - if (c == search && --count == 0) { - pos = it.pos; - break; - } else if (c == current) { + if (c == search && --count == 0) + return it.pos; + else if (c == current) count++; - } } } - return pos; + return pos; /* no match found */ } |
