]> git.neil.brown.name Git - edlib.git/commitdiff
Move <hide> handling to lib-renderlines and fix callers.
authorNeilBrown <neil@brown.name>
Wed, 30 Aug 2023 09:13:59 +0000 (19:13 +1000)
committerNeilBrown <neil@brown.name>
Wed, 30 Aug 2023 09:13:59 +0000 (19:13 +1000)
Complete the <hide> 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 <neil@brown.name>
DOC/TODO.md
lib-markup.c
lib-renderline.c
python/lib-html-w3m.py
python/module-notmuch.py

index 3c3787ea7a6193075500950c4d65e880892263a2..b8cc83c9618f3c3015278d714abfcbabb5a73878 100644 (file)
@@ -15,7 +15,7 @@ the file.
 
 - [X] notmuch addresses in From: list to have menu to add address to any
       from-* query
-- [ ] Disable <hide> if cursor is in the hidden region.
+- [X] Disable <hide> 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 <hide> handling to lib-renderline so we can disable <hide>
+- [X] Move <hide> handling to lib-renderline so we can disable <hide>
       if cursor is in the hidden region.
 
 ### lib-macro
index 75efd2312efee2164edf8f311409730593c0f971..574b4cebfe059aea5f67f9f3fdd58e8ebb5df67f 100644 (file)
@@ -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') {
index bf6e11505ab9cf40a11eece1cded28ec7c1d51c9..cc4dc6bd51cef220e410efde8ddf4e628ecb1da9 100644 (file)
@@ -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;
index 1d074f373b5b01b99a7774afe90f3fb8296bb632..6da8ed2228364b3cdad6a03259e5efe1830697e5 100644 (file)
@@ -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)
index 3b55216066394c302b34e8b8143e59d2840df29b..fc201fd8839bee472ab54861df1d59e4d3f52263 100644 (file)
@@ -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)