]> git.neil.brown.name Git - edlib.git/commitdiff
render-lines: make sure cursor appears in empty file.
authorNeilBrown <neil@brown.name>
Mon, 23 Nov 2015 09:00:05 +0000 (20:00 +1100)
committerNeilBrown <neil@brown.name>
Tue, 24 Nov 2015 00:03:29 +0000 (11:03 +1100)
when point is at the end of a line it is also at the start of the next
line, and this can cause confusion.

Resolve by preferring the start of the next line (even if it is the
non-existent line at end of file) unless the end of the previous line
in not in the first column (e.g. no newline at end-of-file).

Signed-off-by: NeilBrown <neil@brown.name>
render-lines.c

index db3d255f0c2b54f42bc99b4ba68fca5fac901e0d..0ca6ab939b85fb8c5b9ca9a6842ea440eefa61f7 100644 (file)
@@ -155,7 +155,7 @@ static void render_line(struct pane *p, char *line, int *yp, int dodraw,
                int err = mbrtowc(&ch, line, l, &ps);
 
                if (err < 0) {
-                       ch = *line++;
+                       ch = *line;
                        err = 1;
                }
                if (y == cy && x <= cx)
@@ -518,13 +518,13 @@ restart:
                        call_render_line(p, ptp, m);
                }
                m2 = container_of(vmark_next(&m->m), struct rl_mark, m);
-               if (m->line &&
+               if (p->cx <= 0 &&
                    mark_ordered_or_same(d, &m->m, mark_of_point(*ptp)) &&
                    (!m2 || mark_ordered_or_same(d, mark_of_point(*ptp), &m2->m))) {
                        int len = call_render_line_to_point(p, ptp,
                                                            m);
                        rl->cursor_line = y;
-                       render_line(p, m->line, &y, 1, &p->cx, &p->cy, &len);
+                       render_line(p, m->line ?: "", &y, 1, &p->cx, &p->cy, &len);
                        if (p->cy < 0)
                                p->cx = -1;
                        if (!rl->do_wrap && p->cy >= 0 && p->cx < rl->prefix_len) {