From e5dd33175fc7eb69ebc4ad63e94e483ad881008e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sun, 9 Oct 2016 09:21:48 +0200 Subject: vis: fix g_ motion to never cross line boundaries --- text-motions.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'text-motions.c') 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; } -- cgit v1.2.3