From: NeilBrown Date: Fri, 18 Aug 2023 23:00:51 +0000 (+1000) Subject: render-lines: always give cursor offset when measuring cursor line X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=aa49dd234621f976c3b2c9dfccfc8cec27489f18;p=edlib.git render-lines: always give cursor offset when measuring cursor line 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 --- diff --git a/DOC/TODO.md b/DOC/TODO.md index 3cb4c71b..cba0875e 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -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. diff --git a/render-lines.c b/render-lines.c index 3d485991..459a3f95 100644 --- a/render-lines.c +++ b/render-lines.c @@ -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 diff --git a/tests.d/00-basic b/tests.d/00-basic index 8f5d387a..7c8cfff4 100644 --- a/tests.d/00-basic +++ b/tests.d/00-basic @@ -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"