From: NeilBrown Date: Wed, 30 Aug 2023 09:13:59 +0000 (+1000) Subject: Move handling to lib-renderlines and fix callers. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=2b378340486dff65c132ae59c956280c37ddbdbd;p=edlib.git Move handling to lib-renderlines and fix callers. Complete the handling in lib-renderlines and remove it from lib-markup. This showed up various bugs in how it was being used - it was a wonder it ever worked! So fix those bugs in clients too. Signed-off-by: NeilBrown --- diff --git a/DOC/TODO.md b/DOC/TODO.md index 3c3787ea..b8cc83c9 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -15,7 +15,7 @@ the file. - [X] notmuch addresses in From: list to have menu to add address to any from-* query -- [ ] Disable if cursor is in the hidden region. +- [X] Disable if cursor is in the hidden region. - [X] fill mode to handle all punctuation at start of this line - [ ] Enable lib-menu to show short-cut keys - [ ] Add menu-bar to lib-menu. Pop it up on F10 with simple commands @@ -372,7 +372,7 @@ Module features ### lib-markup -- [ ] Move handling to lib-renderline so we can disable +- [X] Move handling to lib-renderline so we can disable if cursor is in the hidden region. ### lib-macro diff --git a/lib-markup.c b/lib-markup.c index 75efd231..574b4ceb 100644 --- a/lib-markup.c +++ b/lib-markup.c @@ -413,8 +413,6 @@ DEF_CMD(render_line) break; } chars++; - if (ar.ast && strcmp(ar.ast->attr, "hide") == 0) - continue; if (ch == '\r' && noret) { /* do nothing */ } else if (ch < ' ' && ch != '\t') { diff --git a/lib-renderline.c b/lib-renderline.c index bf6e1150..cc4dc6bd 100644 --- a/lib-renderline.c +++ b/lib-renderline.c @@ -315,9 +315,9 @@ static void parse_line(struct rline_data *rd safe) /* strip one more ',' */ if (attr.len > 0) attr.len -= 1; - if (attr.len <= wrap_depth) + if (wrap && attr.len <= wrap_depth) wrap = 0; - if (attr.len <= hide_depth) + if (hide && attr.len <= hide_depth) hide = 0; break; case ack: @@ -529,6 +529,7 @@ static int measure_line(struct pane *p safe, struct pane *focus safe, int offset int x, y; int ret = 0; bool seen_rtab = False; + unsigned int offset_hide = 0; if (!rd->content) return ret; @@ -537,6 +538,8 @@ static int measure_line(struct pane *p safe, struct pane *focus safe, int offset offset == rd->measure_offset) { /* No change */ for (ri = rd->content ; ri ; ri = ri->next) { + if (ri->hidden) + continue; if (ri->eol && rd->line[ri->start] == '\n') ret |= 1; if (ri->eol && rd->line[ri->start] == '\f') @@ -569,7 +572,19 @@ static int measure_line(struct pane *p safe, struct pane *focus safe, int offset /* 0 means right edge for right_margin, and left edge for all others */ right_margin = p->w - calc_pos(-rd->right_margin, p->w, rd->curs_width); + if (offset >= 0) + for (ri = rd->content ; ri ; ri = ri->next) + if (offset < ri->start + ri->len) { + offset_hide = ri->hide; + break; + } + for (ri = rd->content; ri; ri = ri->next) { + ri->hidden = (ri->hide && ri->hide != offset_hide); + if (ri->hidden) { + ri->width = 0; + continue; + } if (ri->len == 0 || (unsigned char)rd->line[ri->start] >= ' ') { cr = do_measure(p, ri, 0, -1, -1); @@ -598,7 +613,6 @@ static int measure_line(struct pane *p safe, struct pane *focus safe, int offset if (cr.i2 > rd->ascent) rd->ascent = cr.i2; ri->width = ri->eol ? 0 : cr.x; - ri->hidden = False; if (ri->start <= offset && offset <= ri->start + ri->len) { cr = measure_str(p, "M", ri->attr); @@ -619,6 +633,10 @@ static int measure_line(struct pane *p safe, struct pane *focus safe, int offset int w, margin; struct render_item *ri2; ri->y = y; + if (ri->hidden) { + ri->x = x; + continue; + } if (ri->tab != TAB_UNSET) x = left_margin + calc_pos(ri->tab, right_margin - left_margin, @@ -680,6 +698,8 @@ static int measure_line(struct pane *p safe, struct pane *focus safe, int offset wrap_margin = left_margin + rd->head_length; for (ri = rd->content ; wrap && ri ; ri = ri->next) { int splitpos; + if (ri->hidden) + continue; if (ri->wrap && (wraprl == NULL || ri->wrap != wraprl->wrap)) wraprl = ri; if (ri->wrap_margin) @@ -873,6 +893,8 @@ static int find_xy(struct pane *p safe, struct pane *focus safe, for (r = rd->content; r ; r = r->next) { int split; + if (r->hidden) + continue; if (r->y <= y && r->x <= x) { ri = r; start = r->start; @@ -926,6 +948,8 @@ static struct xy find_curs(struct pane *p safe, int offset, const char **cursatt struct render_item *r, *ri = NULL; for (r = rd->content; r; r = r->next) { + if (r->hidden) + continue; if (offset < r->start) break; ri = r; diff --git a/python/lib-html-w3m.py b/python/lib-html-w3m.py index 1d074f37..6da8ed22 100644 --- a/python/lib-html-w3m.py +++ b/python/lib-html-w3m.py @@ -449,13 +449,13 @@ def parse_halfdump(doc): while i < len: doc.prev(st) i += 1 - doc.call('doc:set-attr', 1, st, "render:hide", "10000") + doc.call('doc:set-attr', 1, st, "render:hide", "1") sol = st.dup() while sol < m: if doc.following(sol) in [ '\n', '\v', '\f' ]: doc.call('doc:set-attr', 1, sol, "markup:not_eol", "1") doc.next(sol) - doc.call('doc:set-attr', 1, m, "render:hide", "-1") + doc.call('doc:set-attr', 1, m, "render:hide", "0") # We only parse entities between tags, not within them parse_entities(doc, prev_end, st) diff --git a/python/module-notmuch.py b/python/module-notmuch.py index 3b552160..fc201fd8 100644 --- a/python/module-notmuch.py +++ b/python/module-notmuch.py @@ -3512,7 +3512,8 @@ class notmuch_message_view(edlib.Pane): comm2("attr:callback", focus, 10000, mark, "word-wrap:0", 120) return 1 if str == "render:hide": - comm2("attr:callback", focus, 10000, mark, "hide", 100000) + comm2("attr:callback", focus, 100000 if str2 == "1" else -1, + mark, "hide", 100000) if str == "render:bold": comm2("attr:callback", focus, 100000 if str2 == "1" else -1, mark, "bold", 120)