diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-10-09 09:21:48 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-10-09 09:26:59 +0200 |
| commit | e5dd33175fc7eb69ebc4ad63e94e483ad881008e (patch) | |
| tree | 733304fad14baa88d780452052bc91217ed4f3ed /text-motions.c | |
| parent | e63c915d694f1dba2eeffb679f3bcfbf9452794d (diff) | |
| download | vis-e5dd33175fc7eb69ebc4ad63e94e483ad881008e.tar.gz vis-e5dd33175fc7eb69ebc4ad63e94e483ad881008e.tar.xz | |
vis: fix g_ motion to never cross line boundaries
Diffstat (limited to 'text-motions.c')
| -rw-r--r-- | text-motions.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/text-motions.c b/text-motions.c index 8af6b7b..884d95c 100644 --- a/text-motions.c +++ b/text-motions.c @@ -144,9 +144,17 @@ size_t text_line_start(Text *txt, size_t pos) { size_t text_line_finish(Text *txt, size_t pos) { char c; - Iterator it = text_iterator_get(txt, text_line_end(txt, pos)); - do text_iterator_char_prev(&it, NULL); - while (text_iterator_byte_get(&it, &c) && c != '\n' && space(c)); + size_t end = text_line_end(txt, pos); + Iterator it = text_iterator_get(txt, end); + if (!text_iterator_char_prev(&it, &c) || c == '\n') + return end; + while (text_iterator_byte_get(&it, &c) && space(c)) { + if (c == '\n') { + it.pos++; + break; + } + text_iterator_char_prev(&it, NULL); + } return it.pos; } |
