]> git.neil.brown.name Git - edlib.git/commitdiff
lib-view: prevent stray clicks from going to parent.
authorNeilBrown <neil@brown.name>
Fri, 8 Sep 2023 06:50:10 +0000 (16:50 +1000)
committerNeilBrown <neil@brown.name>
Fri, 8 Sep 2023 06:50:10 +0000 (16:50 +1000)
Any clicks outside of the child should be stopped from getting to the
parent where generic handing might assume the click is in the document.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
lib-view.c

index f9a179460becdfa971b349a29194a90b9db531d9..3f6262242cccd77f7642c78366b8e8c1982b3565 100644 (file)
@@ -13,7 +13,7 @@ the file.
 - [X] From start-of-file move to end, then up, then down.
       Display jumps.  Why?
 - [ ] Add menubar menu with recent documents?
-- [ ] why does clicking on status line go to top-of-file?
+- [X] why does clicking on status line go to top-of-file?
 - [ ] should Docs menu go on doc name in status bar?
 - [X] search hangs when seeking "^( *)"
 - [ ] selection-menu item to show git-commit from list of known git
@@ -76,6 +76,9 @@ Requirements for a v1.0 release
 Core features
 -------------
 
+- [ ] If a pane wants to block mouse events from parents, as lib-view
+      does, it shouldn't need to catch all the combinations, or it
+      should be much easier
 - [ ] gather memory usage stats per-pane and allow a dump
 - [ ] show doc size in doc list - include undo size?
 - [ ] Ensure all panes that should use "Free" properly, and find some
index 53fa807c6edf5f45174efb862aa352fae4a475e2..f27fb2738a74db6d7bd2038d06f6cbc7abf994c3 100644 (file)
@@ -443,6 +443,7 @@ DEF_CMD(view_click)
 {
        struct pane *p = ci->home;
        struct view_data *vd = p->data;
+       struct pane *c = vd->child;
        int mid = vd->scroll_bar_y;
        int lh = vd->line_height;
        int num;
@@ -451,10 +452,20 @@ DEF_CMD(view_click)
 
        cih = pane_mapxy(ci->focus, ci->home, ci->x, ci->y, False);
 
-       if (cih.x >= vd->border_width)
+       if (ci->focus != p)
+               /* Event was in the child */
                return Efallthrough;
+       if (!c)
+               return 1;
+       /* Ignore if not in scroll-bar, which it to left of child */
+       if (cih.y < c->y ||             // above child
+           cih.y >= c->y + c->h ||     // below child
+           cih.x >= c->x)              // Not to right of child
+               return 1;
+
        if (p->h <= 4)
-               return Efallthrough;
+               /* scroll bar too small to be useful */
+               return 1;
 
        scale = 100; /* 10% for small movements */
        num = RPT_NUM(ci);
@@ -476,6 +487,16 @@ DEF_CMD(view_click)
        return 1;
 }
 
+DEF_CMD(view_release)
+{
+       /* Make sure release doesn't go to parent if not in child */
+
+       if (ci->focus != ci->home)
+               /* Event was in the child */
+               return Efallthrough;
+       return 1;
+}
+
 DEF_CMD(view_scroll)
 {
        if (strcmp(ci->key, "M:Press-4") == 0)
@@ -528,6 +549,9 @@ void edlib_init(struct pane *ed safe)
 
        key_add(view_map, "M:Click-1", &view_click);
        key_add(view_map, "M:Press-1", &view_click);
+       key_add(view_map, "M:Release-1", &view_release);
+       key_add(view_map, "M:DPress-1", &view_click);
+       key_add(view_map, "M:TPress-1", &view_click);
        key_add(view_map, "M:Press-4", &view_scroll);
        key_add(view_map, "M:Press-5", &view_scroll);
        key_add(view_map, "Window:border", &view_border);