]> git.neil.brown.name Git - edlib.git/commitdiff
render-lines: always give cursor offset when measuring cursor line
authorNeilBrown <neil@brown.name>
Fri, 18 Aug 2023 23:00:51 +0000 (09:00 +1000)
committerNeilBrown <neil@brown.name>
Sun, 20 Aug 2023 22:46:08 +0000 (08:46 +1000)
As presence of cursor can change size of appearance, we need to always
report where the cursor is when measuring the line.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
render-lines.c
tests.d/00-basic

index 3cb4c71bbec827fdfafa37787adbe9625b4a449e..cba0875e2bd78224307347ea80b58a25795e9954 100644 (file)
@@ -22,14 +22,14 @@ the file.
 - [X] merge command 9-A-m could work as one command.  If there is an
       active selection, the patch is moved to that selection.
 - [X] merge command 9 must ensure selection is full lines.
-- [ ] if cursor position causes pane size to change, this doesn't
+- [X] if cursor position causes pane size to change, this doesn't
       propagate.
 - [ ] When is left_margin used?  Can I use it for hanging indent?  If
       not, how do I do that?  Can I tab out, set margin, tab back for
       text?  Am I using points properly?
 - [X] find a better way to handle "case when EOF is at the end" of
       a non-empty line.
-- [ ] as renderline changes result if cursor is present, cursor pos
+- [X] as renderline changes result if cursor is present, cursor pos
       must ALWAYS be given.
 - [ ] write test view mode that treats each line in document as markup
       so markup can be tested more directly.
index 3d48599199b3a522807c4eaf6673382cfa53be8c..459a3f95bcd53389249884ff319623c279eb7140 100644 (file)
@@ -1115,16 +1115,32 @@ static int revalidate_start(struct rl_data *rl safe,
        start_of_file = doc_prior(focus, start) == WEOF;
        for (m = start; m && !found_end && y < p->h; m = vmark_next(m)) {
                struct pane *hp;
-               int found;
+               int found = 0;
+               int offset = -1;
                if (refresh_all)
                        vmark_invalidate(m);
                call_render_line(p, focus, m, NULL);
-               found = measure_line(p, focus, m);
-               found_end = found & 2;
+               m2 = vmark_next(m);
+               /* The "found & 1" handles case when EOF is at the end
+                * of a non-empty line.
+                */
+               if (pm && m2 && mark_same(pm, m2))
+                       /* Cursor at end shouldn't affect appearance */
+                       found = measure_line(p, focus, m);
+               if (pm && m2 && mark_ordered_or_same(m, pm) &&
+                   (mark_ordered_not_same(pm, m2) ||
+                    (mark_same(pm, m2) && !(found & 1))))
+                       /* Cursor is on this line */
+                       offset = call_render_line_to_point(focus,
+                                                          pm, m);
+               found = measure_line(p, focus, m, offset);
+
                hp = m->mdata;
                if (!mark_valid(m) || !hp)
                        break;
 
+               found_end = found & 2;
+
                if (y != hp->y) {
                        pane_damaged(p, DAMAGED_REFRESH);
                        hp->damaged &= ~DAMAGED_SIZE;
@@ -1133,23 +1149,13 @@ static int revalidate_start(struct rl_data *rl safe,
                                pane_damaged(hp, DAMAGED_REFRESH);
                }
                y += hp->h;
-               m2 = vmark_next(m);
-               /* The "found & 1" handles case when EOF is at the end
-                * of a non-empty line.
-                */
-               if (pm && m2 && mark_ordered_or_same(m, pm) &&
-                   (mark_ordered_not_same(pm, m2) ||
-                    (mark_same(pm, m2) && !(found & 1)))) {
-
+               if (offset >= 0) {
                        /* Cursor is on this line */
-                       int offset = call_render_line_to_point(focus,
-                                                              pm, m);
                        int lh = attr_find_int(hp->attrs,
                                               "line-height");
                        int cy = y - hp->h + hp->cy;
                        if (lh < 1)
                                lh = 1;
-                       measure_line(p, focus, m, offset);
                        if (m == start && rl->skip_height > 0) {
                                /* Point might be in this line, but off top
                                 * of the screen
index 8f5d387a8841b1b8837ac9c6d7e16ad43c558529..7c8cfff423898699c14507b29f2aa5176614b6e1 100644 (file)
@@ -707,9 +707,9 @@ Display 80,30 EC2C0C5779D217786DBF72009BC289A2 4,7
 Key "- "
 Display 80,30 A84DE4E3F90DB9F454DC6BDD158DAEC4 5,7
 Key "- "
-Display 80,30 21D172645F11E5F6F6A2B853FB151B23 6,7
+Display 80,30 3C812011C331AE6C522C00B0145F9E4D 6,7
 Key ":C-F"
-Display 80,30 21D172645F11E5F6F6A2B853FB151B23 7,7
+Display 80,30 3C812011C331AE6C522C00B0145F9E4D 7,7
 Key ":C-F"
 Display 80,30 68CC3869602D7CE09C8CB343CB22E8D9 2,7
 Key ":C-X"