vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit f4e671ea73fb1544956e5ab3f3308f077f1577d6 parent 4405f21a18f359c69699aecc232d6a2483b6837b Author: Marc André Tanner <mat@brain-dump.org> Date: Sun, 9 Oct 2016 09:21:48 +0200 vis: fix g_ motion to never cross line boundaries Diffstat:
| M | text-motions.c | | | 14 | +++++++++++--- |
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git 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; }