diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-08-07 22:33:43 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-08-07 22:33:43 +0200 |
| commit | 2425c1614f51c1c3641ccd2c99f3e751c8ceb421 (patch) | |
| tree | c5768f95e0062d8bf9e9b5ede66109371e957570 /text-motions.c | |
| parent | fd89e4dd1418d1474894d09c0ea8418f32dba490 (diff) | |
| download | vis-2425c1614f51c1c3641ccd2c99f3e751c8ceb421.tar.gz vis-2425c1614f51c1c3641ccd2c99f3e751c8ceb421.tar.xz | |
vis: limit to/till movements to current line
Diffstat (limited to 'text-motions.c')
| -rw-r--r-- | text-motions.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/text-motions.c b/text-motions.c index 97012bd..aa779b2 100644 --- a/text-motions.c +++ b/text-motions.c @@ -46,7 +46,7 @@ size_t text_char_prev(Text *txt, size_t pos) { return it.pos; } -size_t text_find_next(Text *txt, size_t pos, const char *s) { +static size_t find_next(Text *txt, size_t pos, const char *s, bool line) { if (!s) return pos; size_t len = strlen(s), matched = 0; @@ -61,11 +61,21 @@ size_t text_find_next(Text *txt, size_t pos, const char *s) { matched = 0; } text_iterator_byte_next(&it, NULL); + if (line && c == '\n') + break; } return matched == len ? it.pos - len : pos; } -size_t text_find_prev(Text *txt, size_t pos, const char *s) { +size_t text_find_next(Text *txt, size_t pos, const char *s) { + return find_next(txt, pos, s, false); +} + +size_t text_line_find_next(Text *txt, size_t pos, const char *s) { + return find_next(txt, pos, s, true); +} + +static size_t find_prev(Text *txt, size_t pos, const char *s, bool line) { if (!s) return pos; size_t len = strlen(s), matched = len - 1; @@ -84,10 +94,20 @@ size_t text_find_prev(Text *txt, size_t pos, const char *s) { matched = len - 1; } text_iterator_byte_prev(&it, NULL); + if (line && c == '\n') + break; } return matched == 0 ? it.pos : pos; } +size_t text_find_prev(Text *txt, size_t pos, const char *s) { + return find_prev(txt, pos, s, false); +} + +size_t text_line_find_prev(Text *txt, size_t pos, const char *s) { + return find_prev(txt, pos, s, true); +} + size_t text_line_prev(Text *txt, size_t pos) { char c; Iterator it = text_iterator_get(txt, pos); |
