From f379b9470c05fdabb9ab4b1a7e1101634cd254c0 Mon Sep 17 00:00:00 2001 From: Factor Date: Thu, 19 Nov 2026 20:18:20 +0100 Subject: [PATCH] fix: a click on a panel row does not reach the bar under it Co-Authored-By: Ovis Fast (Claude) --- .../mods/herdr-composer/dock.js | 13 ++++++++++ .../mods/herdr-composer/main.js | 25 ++++++++++++++++--- tests/dock.test.mjs | 8 +++++- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/herdr/herdr-composer/mods/herdr-composer/dock.js b/herdr/herdr-composer/mods/herdr-composer/dock.js index 78145c5..cf43f3f 100644 --- a/herdr/herdr-composer/mods/herdr-composer/dock.js +++ b/herdr/herdr-composer/mods/herdr-composer/dock.js @@ -277,3 +277,16 @@ export function add(dock, { id, text, label, mode }) { { id, label: name === "" ? defaultLabel(clean) : name, text: clean, mode: mode === "insert" ? "insert" : "send" }, ]; } + +/** + * True while `now` is less than `ms` after `at`: the click that closed + * something is still the same click. + * + * @param {number} now + * @param {number} at + * @param {number} ms + * @returns {boolean} + */ +export function withinGuard(now, at, ms) { + return now - at < ms; +} diff --git a/herdr/herdr-composer/mods/herdr-composer/main.js b/herdr/herdr-composer/mods/herdr-composer/main.js index 2d4a246..e1ceb17 100644 --- a/herdr/herdr-composer/mods/herdr-composer/main.js +++ b/herdr/herdr-composer/mods/herdr-composer/main.js @@ -82,6 +82,7 @@ import { menuTransition, applyDock, add as addButton, + withinGuard, DOCK_LIMIT, } from "./dock.js"; import { @@ -272,6 +273,7 @@ export default class Composer extends View { this.contextMenu = null; this.menuOpenedAt = 0; this.menuClosedAt = 0; + this.panelClosedAt = 0; this.renameRefocused = false; this.renaming = null; this.renameStartedAt = 0; @@ -782,6 +784,7 @@ export default class Composer extends View { if (!this.panel) return; const { caret } = this.panel; this.panel = null; + this.panelClosedAt = Date.now(); if (this.contextMenu?.kind === "row") this.dropContextMenu(); this.panelSearchFocused = false; if (this.panelRestorePx !== null) { @@ -1131,6 +1134,8 @@ export default class Composer extends View { /** What the open/close signal of a `Popover` does to the state of the menu. */ popoverChanged(kind, id, open, cx) { + // The click that closed the panel must not open a menu of the bar under it. + if (open && this.panelJustClosed()) return; const now = Date.now(); // A "closed" that comes in the moment the menu opened is the old menu's // dismissal landing on the new press: the menu stays. @@ -1153,6 +1158,11 @@ export default class Composer extends View { cx.notify(); } + /** The panel closed a moment ago: a click now is the click that closed it, not a click on the bar under it. */ + panelJustClosed() { + return withinGuard(Date.now(), this.panelClosedAt, 250); + } + /** The menu is closed (or was a moment ago): a click now is the click that closed it. */ menuBusy() { return this.contextMenu !== null || Date.now() - this.menuClosedAt < 150; @@ -3110,7 +3120,7 @@ export default class Composer extends View { */ dockPress(button, cx) { // The click that closed a menu (or lands while one is open) is not a press. - if (this.menuBusy()) return; + if (this.menuBusy() || this.panelJustClosed()) return; const hasAgent = Boolean(this.target()); const action = dockAction(button, { hasAgent }); if (action === "none" || !hasAgent) return; @@ -3184,6 +3194,7 @@ export default class Composer extends View { .cursor_pointer() .hover((s) => s.bg(t.hover).text_color(lit ? t.working : t.foreground)) .on_click((event, cx) => { + if (this.panelJustClosed()) return; if (enabled) action(event, cx); }) .child(glyph); @@ -3204,7 +3215,10 @@ export default class Composer extends View { .text_color(agent ? t.muted : t.dim) .cursor_pointer() .hover((s) => s.bg(t.hover).text_color(t.foreground)) - .on_click((event, cx) => this.pickFiles(cx)) + .on_click((event, cx) => { + if (this.panelJustClosed()) return; + this.pickFiles(cx); + }) .child("+"); } @@ -3347,7 +3361,7 @@ export default class Composer extends View { .cursor_pointer() .when(!disabled, (el) => el.hover((s) => s.opacity(0.88))) .on_click((event, cx) => { - if (!disabled) this.submit(this.value, cx); + if (!disabled && !this.panelJustClosed()) this.submit(this.value, cx); }) .child( div() @@ -3370,7 +3384,10 @@ export default class Composer extends View { .justify_center() .cursor_pointer() .hover((s) => s.opacity(0.85)) - .on_click((event, cx) => this.interrupt(agent, cx)) + .on_click((event, cx) => { + if (this.panelJustClosed()) return; + this.interrupt(agent, cx); + }) .child(div().size(10).rounded(2).bg(t.background)); } diff --git a/tests/dock.test.mjs b/tests/dock.test.mjs index 686aae2..be813c8 100644 --- a/tests/dock.test.mjs +++ b/tests/dock.test.mjs @@ -2,7 +2,7 @@ import test from "node:test"; import assert from "node:assert/strict"; import { DOCK_LIMIT, LABEL_MAX, defaultLabel, normalize, isPinned, pin, unpin, remove, move, - rename, toggleMode, dockAction, dockMenu, rowMenu, starMenu, menuTransition, applyDock, add, + rename, toggleMode, dockAction, dockMenu, rowMenu, starMenu, menuTransition, applyDock, add, withinGuard, } from "../herdr/herdr-composer/mods/herdr-composer/dock.js"; const btn = (id, text, extra = {}) => ({ id, label: text, text, mode: "send", ...extra }); @@ -170,3 +170,9 @@ test("add: label, mode, empty text, duplicate, limit", () => { assert.equal(add(full, { id: "n", text: "new", label: "", mode: "send" }), full); assert.equal(add([], { id: "1", text: "x", label: "", mode: "bogus" })[0].mode, "send"); }); + +test("withinGuard: only just after the moment", () => { + assert.equal(withinGuard(1100, 1000, 250), true); + assert.equal(withinGuard(1250, 1000, 250), false); + assert.equal(withinGuard(5000, 0, 250), false); +});