martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.26k stars 259 forks source link

Vis moves to wrapped portion of last line #873

Closed DavPalma closed 4 years ago

DavPalma commented 4 years ago

When we have the cursor in the last line and the text in that line is wrapped, moving down will move the cursor to the wrapped portion as if it was another real line. The reason for this appears to be the two newlines at the end of the file, and since these characters are in the same line and text_line_next will return the position of the last newline character.

martanne commented 4 years ago

Hi, I don't think changing text_line_next is a good idea. Conceptually you eventually want to reach the end of the file when repeatedly calling it.

The following might work (not really tested):

diff --git a/text-motions.c b/text-motions.c
index 21967e5..1430d49 100644
--- a/text-motions.c
+++ b/text-motions.c
@@ -287,6 +287,8 @@ size_t text_line_up(Text *txt, size_t pos) {
 size_t text_line_down(Text *txt, size_t pos) {
    int width = text_line_width_get(txt, pos);
    size_t next = text_line_next(txt, pos);
+   if (next == text_size(txt))
+       return pos;
    return text_line_width_set(txt, next, width);
 }
DavPalma commented 4 years ago

Hi, I have just tested it and it seems to be working as intended now.

Thank You.