]> git.neil.brown.name Git - edlib.git/commitdiff
notmuch: when toggling visibility, ensure to move point.
authorNeilBrown <neil@brown.name>
Sun, 5 Feb 2023 20:50:04 +0000 (07:50 +1100)
committerNeilBrown <neil@brown.name>
Mon, 6 Feb 2023 05:48:19 +0000 (16:48 +1100)
When a Mouse-Activate message arrives, the mark is not the point, so
moving it to the previous part is pointless.  Find the mark and move it.

Also do this whenever visibility changes at all.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
doc-email.c
python/module-notmuch.py

index 3d29ad36b592ce7f587e89e40c8408f31b7207c6..1ce2a7f06c0fb92661c281eec308e58f023b3266 100644 (file)
@@ -662,7 +662,8 @@ Module features
     redraw gets confused and point goes off-screen, which seems
     to leave it confused.
 - [ ] in text/plain, wrap long lines on 'space'. - make this a config in lib-markup
-- [1] allow view of all headers, and of "more" than default (including file names)
+- [X] allow view of all headers
+- [1] allow view of "more" headers than default (including file names, message-id)
 - [ ] maybe hide signature, unless small
 - [ ] When click on first char in tagged range, I don't see the tag and
    don't get a Mouse-Activate event.
index 40b062df0a85e2004cb0c8d27e24d2605bc5e073..51a4f889b017f4f9190c1861b0440627146b6232 100644 (file)
@@ -111,6 +111,7 @@ DEF_CMD(email_spacer)
 {
        struct buf b;
        int visible = 1;
+       int orig = 0;
        struct mark *m = ci->mark;
        struct mark *pm = ci->mark2;
        int o = ci->num;
@@ -146,6 +147,8 @@ DEF_CMD(email_spacer)
        attr = pane_mark_attr(ci->focus, m, "email:visible");
        if (attr && strcmp(attr, "none") == 0)
                visible = 0;
+       if (attr && strcmp(attr, "orig") == 0)
+               orig = 1;
        attr = pane_mark_attr(ci->home, m, "multipart-prev:email:actions");
        if (!attr)
                attr = "hide";
@@ -157,6 +160,9 @@ DEF_CMD(email_spacer)
                if (is_attr("hide", attr))
                        ok = cond_append(&b, visible ? "HIDE" : "SHOW", attr,
                                         o, &cp);
+               else if (is_attr("full", attr))
+                       ok = cond_append(&b, orig ? "BRIEF" : "FULL", attr,
+                                        o, &cp);
                else
                        ok = cond_append(&b, attr, attr, o, &cp);
                if (ok)
@@ -293,6 +299,23 @@ DEF_CMD(email_select_hide)
        return 1;
 }
 
+DEF_CMD(email_select_full)
+{
+       int want_orig = 1;
+       char *a;
+       struct mark *m = ci->mark;
+
+       if (!m)
+               return Enoarg;
+
+       a = pane_mark_attr(ci->focus, m, "email:visible");
+       if (a && strcmp(a, "orig") == 0)
+               want_orig = 0;
+       call("doc:set-attr", ci->focus, 1, m, "email:visible", 0, NULL,
+            want_orig ? "orig" : "transformed");
+       return 1;
+}
+
 static struct map *email_view_map safe;
 
 DEF_LOOKUP_CMD(email_view_handle, email_view_map);
@@ -719,13 +742,15 @@ static bool handle_rfc822(struct pane *email safe,
                          struct pane *mp safe, struct pane *spacer safe,
                          char *path safe)
 {
-       struct pane *h2;
+       struct pane *h2, *h3;
        struct pane *hdrdoc = NULL;
        struct mark *point = NULL;
+       struct mark *hdr_start;
        char *xfer = NULL, *type = NULL, *disp = NULL;
        char *mime;
        char *newpath = NULL;
 
+       hdr_start = mark_dup(start);
        h2 = call_ret(pane, "attach-rfc822header", email, 0, start, NULL, 0, end);
        if (!h2)
                goto out;
@@ -765,12 +790,15 @@ static bool handle_rfc822(struct pane *email safe,
 
        newpath = NULL;
        asprintf(&newpath, "%s%sheaders", path, path[0] ? ",":"");
-       attr_set_str(&hdrdoc->attrs, "email:actions", "hide");
+       attr_set_str(&hdrdoc->attrs, "email:actions", "hide:full");
        attr_set_str(&hdrdoc->attrs, "email:which", "transformed");
        attr_set_str(&hdrdoc->attrs, "email:content-type", "text/rfc822-headers");
        attr_set_str(&hdrdoc->attrs, "email:path", newpath);
        attr_set_str(&hdrdoc->attrs, "email:is_transformed", "yes");
-       home_call(mp, "multipart-add", h2);
+       h3 = call_ret(pane, "attach-crop", h2, 0, hdr_start, NULL, 0, start);
+       if (!h3)
+               h3 = h2;
+       home_call(mp, "multipart-add", h3);
        home_call(mp, "multipart-add", hdrdoc);
        home_call(mp, "multipart-add", spacer);
        free(newpath);
@@ -1138,6 +1166,7 @@ static void email_init_map(void)
        key_add(email_view_map, "doc:email:render-image", &email_image);
        key_add(email_view_map, "doc:email:select", &email_select);
        key_add(email_view_map, "email:select:hide", &email_select_hide);
+       key_add(email_view_map, "email:select:full", &email_select_full);
 }
 
 void edlib_init(struct pane *ed safe)
index d63ea6dbdbd519db7bdf87ec72ee83af45cf2134..1a06072cc11fb5ece6eb2987ca8b6f2fba84a6c9 100644 (file)
@@ -3347,13 +3347,15 @@ class notmuch_message_view(edlib.Pane):
         return 1
 
     def handle_toggle_vis(self, key, focus, mark, **a):
-        "handle-list/Mouse-Activate:email-hide/email:select:hide"
+        "handle-list/Mouse-Activate:email-hide/email:select:hide/Mouse-Activate:email-full/email:select:full"
         v = focus.call("doc:get-attr", mark, "email:visible", ret='str')
-        self.parent.call("email:select:hide", focus, mark)
+        self.parent.call("email:select:" + key[-4:], focus, mark)
         v2 = focus.call("doc:get-attr", mark, "email:visible", ret='str')
-        if v == "none" and v2 != "none":
-            # when making visible, move point to start
+        if v != v2:
+            # when visibility changes, move point to start.
             focus.call("doc:email-step-part", mark, -1)
+            pt = focus.call("doc:point", ret='mark');
+            pt.to_mark(mark)
         return 1
 
     def handle_save(self, key, focus, mark, **a):