From 581baad592d1a7a46352649967afed97cb93064d Mon Sep 17 00:00:00 2001 From: Loren McIntyre Date: Fri, 11 Sep 2026 12:33:12 -0700 Subject: [PATCH] feat(nav-popups): keep ancestor popups open while a subpopup is hovered MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Upstream's posCheckerHook hides a popup once the cursor leaves its box — which happens the moment you move into a subpopup opened from a link inside it, so the parent disappears under the child and there's no way back up the chain. Add isOverPopupTree(): the cursor counts as over a popup while it's within (or over an open menu of) any visible popup whose parentPopup chain reaches it. Gated by a new option popupKeepParentsOpen (default true in this fork; false restores upstream). Leaving the whole tree still hides every level on its own popupHideDelay. The helper is pure (links + menu predicate injected) and unit-tested by source extraction; a text test pins the option + hook wiring. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_015rGhsPz9LskDBTRc42v82t --- mw/README.md | 8 +++ mw/nav-popups/popups.js | 44 +++++++++++++- tampermonkey/test/nav-popups-patch.test.js | 70 ++++++++++++++++++++++ 3 files changed, 119 insertions(+), 3 deletions(-) diff --git a/mw/README.md b/mw/README.md index dafa855..90e7b8d 100644 --- a/mw/README.md +++ b/mw/README.md @@ -54,6 +54,14 @@ stays legible and re-appliable after an upstream refresh. Current live deltas: (Open: user-editable style overrides from userscript land — would need a store site pages can't write, e.g. `GM_setValue`, and no remote refs / interpolation in the CSS. Not built.) +- **Ancestor keep-open** (`popupKeepParentsOpen`, default on) — upstream hides + a popup the moment the cursor leaves its box, including when it moved into a + *subpopup* opened from a link inside it, so the parent vanishes under the + child. `isOverPopupTree()` (pure helper, unit-tested) treats the cursor as + still over a popup while it's within, or over an open menu of, any visible + popup whose `parentPopup` chain reaches it. Leaving the whole tree hides + each level on its own `popupHideDelay`, deepest first. Set the option to + `false` for upstream behaviour. ## Tool & version diff --git a/mw/nav-popups/popups.js b/mw/nav-popups/popups.js index ea7ee6c..86ad806 100644 --- a/mw/nav-popups/popups.js +++ b/mw/nav-popups/popups.js @@ -4067,6 +4067,35 @@ $(() => { Navpopup.tracker.addHook(posCheckerHook(a.navpopup)); } + // LOCAL MOD (mcint/userscripts): ancestor keep-open. Upstream hides a popup + // as soon as the cursor leaves its box — including when the cursor moved + // into a *subpopup* opened from a link inside it, so the parent vanishes + // under the child. Treat the cursor as still over `navpop` while it is + // within (or over an open menu of) any visible popup whose parentPopup + // chain reaches navpop. Pure: links + menu predicate are injected. + function isOverPopupTree(navpop, x, y, links, hasOpenMenu) { + if (navpop.isWithin(x, y)) { + return true; + } + for (let i = 0; links && i < links.length; ++i) { + const p = links[i].navpopup; + if (!p || p === navpop || !p.isVisible()) { + continue; + } + let anc = p.parentPopup; + while (anc && anc !== navpop) { + anc = anc.parentPopup; + } + if (anc !== navpop) { + continue; + } + if (p.isWithin(x, y) || hasOpenMenu(p)) { + return true; + } + } + return false; + } + function posCheckerHook(navpop) { return function () { if (!navpop.isVisible()) { @@ -4077,9 +4106,16 @@ $(() => { } const x = Navpopup.tracker.x, y = Navpopup.tracker.y; - const mouseOverNavpop = - navpop.isWithin(x, y, navpop.fuzz, navpop.mainDiv) || - !fuzzyCursorOffMenus(x, y, navpop.fuzz, navpop.mainDiv); + // LOCAL MOD (mcint/userscripts): with popupKeepParentsOpen, a visible + // subpopup (or its open menu) under the cursor keeps this one open. + // Upstream original was: + // const mouseOverNavpop = + // navpop.isWithin(x, y, navpop.fuzz, navpop.mainDiv) || + // !fuzzyCursorOffMenus(x, y, navpop.fuzz, navpop.mainDiv); + const menuOpen = (p) => !fuzzyCursorOffMenus(x, y, p.fuzz, p.mainDiv); + const mouseOverNavpop = getValueOf('popupKeepParentsOpen') + ? isOverPopupTree(navpop, x, y, pg.current.links, menuOpen) || menuOpen(navpop) + : navpop.isWithin(x, y, navpop.fuzz, navpop.mainDiv) || menuOpen(navpop); // FIXME it'd be prettier to do this internal to the Navpopup objects let t = getValueOf('popupHideDelay'); @@ -9423,6 +9459,8 @@ html.skin-theme-clientpref-night .popup_menu:hover { newOption('popupAppendRedirNavLinks', true); newOption('popupTocLinks', false); newOption('popupSubpopups', true); + // LOCAL MOD (mcint/userscripts): keep ancestor popups open while a subpopup is hovered + newOption('popupKeepParentsOpen', true); newOption('popupDragHandle', false /* 'popupTopLinks'*/); newOption('popupLazyPreviews', true); newOption('popupLazyDownloads', true); diff --git a/tampermonkey/test/nav-popups-patch.test.js b/tampermonkey/test/nav-popups-patch.test.js index 6e7047b..61711c8 100644 --- a/tampermonkey/test/nav-popups-patch.test.js +++ b/tampermonkey/test/nav-popups-patch.test.js @@ -85,3 +85,73 @@ test('needsBaseStyles: false when our style element is already injected', () => assert.strictEqual(needsBaseStyles(doc, getComputedStyle), false); assert.strictEqual(appended.length, 0, 'no probe when already injected'); }); + +// isOverPopupTree(navpop, x, y, links, hasOpenMenu): the cursor counts as +// "over" a popup if it's within the popup itself, or within any *visible +// descendant* popup (one whose parentPopup chain reaches navpop), or over an +// open menu of any of those. Lets ancestors stay open while a subpopup is. +function fakePopup(name, { visible = true, box = null, parent = null } = {}) { + return { + name, + parentPopup: parent, + visible, + isVisible() { return this.visible; }, + isWithin(x, y) { + if (!this.visible || !box) return false; + return x >= box[0] && x <= box[2] && y >= box[1] && y <= box[3]; + }, + }; +} +const linksOf = (...pops) => pops.map((p) => ({ navpopup: p })); + +test('isOverPopupTree: within the popup itself', () => { + const f = extractFn('isOverPopupTree'); + const root = fakePopup('root', { box: [0, 0, 100, 100] }); + assert.strictEqual(f(root, 50, 50, linksOf(root), () => false), true); + assert.strictEqual(f(root, 500, 500, linksOf(root), () => false), false); +}); + +test('isOverPopupTree: within a visible child or grandchild keeps the ancestor', () => { + const f = extractFn('isOverPopupTree'); + const root = fakePopup('root', { box: [0, 0, 100, 100] }); + const child = fakePopup('child', { box: [200, 200, 300, 300], parent: root }); + const grand = fakePopup('grand', { box: [400, 400, 500, 500], parent: child }); + const links = linksOf(root, child, grand); + assert.strictEqual(f(root, 250, 250, links, () => false), true, 'child'); + assert.strictEqual(f(root, 450, 450, links, () => false), true, 'grandchild'); + assert.strictEqual(f(child, 450, 450, links, () => false), true, 'child kept by grandchild'); + assert.strictEqual(f(child, 50, 50, links, () => false), false, 'parent does not keep child'); +}); + +test('isOverPopupTree: hidden descendants and unrelated popups do not count', () => { + const f = extractFn('isOverPopupTree'); + const root = fakePopup('root', { box: [0, 0, 100, 100] }); + const hidden = fakePopup('hidden', { box: [200, 200, 300, 300], parent: root, visible: false }); + const other = fakePopup('other', { box: [600, 600, 700, 700] }); + const links = linksOf(root, hidden, other); + assert.strictEqual(f(root, 250, 250, links, () => false), false, 'hidden child'); + assert.strictEqual(f(root, 650, 650, links, () => false), false, 'unrelated popup'); +}); + +test('isOverPopupTree: an open menu on a visible descendant counts', () => { + const f = extractFn('isOverPopupTree'); + const root = fakePopup('root', { box: [0, 0, 100, 100] }); + const child = fakePopup('child', { box: [200, 200, 300, 300], parent: root }); + const links = linksOf(root, child); + assert.strictEqual(f(root, 999, 999, links, (p) => p === child), true); + assert.strictEqual(f(root, 999, 999, links, () => false), false); +}); + +test('isOverPopupTree tolerates missing links list', () => { + const f = extractFn('isOverPopupTree'); + const root = fakePopup('root', { box: [0, 0, 100, 100] }); + assert.strictEqual(f(root, 50, 50, undefined, () => false), true); + assert.strictEqual(f(root, 500, 500, null, () => false), false); +}); + +test('popupKeepParentsOpen option exists and is wired into posCheckerHook', () => { + assert.match(src, /newOption\('popupKeepParentsOpen', true\)/); + const hook = src.slice(src.indexOf('function posCheckerHook('), src.indexOf('function runStopPopupTimer(')); + assert.match(hook, /getValueOf\('popupKeepParentsOpen'\)/); + assert.match(hook, /isOverPopupTree\(/); +}); -- knotmirror 0.0.1