From: NeilBrown Date: Fri, 8 Sep 2023 06:50:10 +0000 (+1000) Subject: lib-view: prevent stray clicks from going to parent. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=a7f9ec549d7ae57b073d35e07548ef8d2d8f0529;p=edlib.git lib-view: prevent stray clicks from going to parent. 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 --- diff --git a/DOC/TODO.md b/DOC/TODO.md index f9a17946..3f626224 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -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 diff --git a/lib-view.c b/lib-view.c index 53fa807c..f27fb273 100644 --- a/lib-view.c +++ b/lib-view.c @@ -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);