fix: a click on a panel row does not reach the bar under it

Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
FactorandOvis Fast committed 2026-11-19 20:18:20 +01:00
1 parent 000df780be
commit f379b9470c
3 files changed
+41 -5

No files matched your search

@@ -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" }, { 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;
}
@@ -82,6 +82,7 @@ import {
menuTransition, menuTransition,
applyDock, applyDock,
add as addButton, add as addButton,
withinGuard,
DOCK_LIMIT, DOCK_LIMIT,
} from "./dock.js"; } from "./dock.js";
import { import {
@@ -272,6 +273,7 @@ export default class Composer extends View {
this.contextMenu = null; this.contextMenu = null;
this.menuOpenedAt = 0; this.menuOpenedAt = 0;
this.menuClosedAt = 0; this.menuClosedAt = 0;
this.panelClosedAt = 0;
this.renameRefocused = false; this.renameRefocused = false;
this.renaming = null; this.renaming = null;
this.renameStartedAt = 0; this.renameStartedAt = 0;
@@ -782,6 +784,7 @@ export default class Composer extends View {
if (!this.panel) return; if (!this.panel) return;
const { caret } = this.panel; const { caret } = this.panel;
this.panel = null; this.panel = null;
this.panelClosedAt = Date.now();
if (this.contextMenu?.kind === "row") this.dropContextMenu(); if (this.contextMenu?.kind === "row") this.dropContextMenu();
this.panelSearchFocused = false; this.panelSearchFocused = false;
if (this.panelRestorePx !== null) { 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. */ /** What the open/close signal of a `Popover` does to the state of the menu. */
popoverChanged(kind, id, open, cx) { 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(); const now = Date.now();
// A "closed" that comes in the moment the menu opened is the old menu's // A "closed" that comes in the moment the menu opened is the old menu's
// dismissal landing on the new press: the menu stays. // dismissal landing on the new press: the menu stays.
@@ -1153,6 +1158,11 @@ export default class Composer extends View {
cx.notify(); 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. */ /** The menu is closed (or was a moment ago): a click now is the click that closed it. */
menuBusy() { menuBusy() {
return this.contextMenu !== null || Date.now() - this.menuClosedAt < 150; return this.contextMenu !== null || Date.now() - this.menuClosedAt < 150;
@@ -3110,7 +3120,7 @@ export default class Composer extends View {
*/ */
dockPress(button, cx) { dockPress(button, cx) {
// The click that closed a menu (or lands while one is open) is not a press. // 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 hasAgent = Boolean(this.target());
const action = dockAction(button, { hasAgent }); const action = dockAction(button, { hasAgent });
if (action === "none" || !hasAgent) return; if (action === "none" || !hasAgent) return;
@@ -3184,6 +3194,7 @@ export default class Composer extends View {
.cursor_pointer() .cursor_pointer()
.hover((s) => s.bg(t.hover).text_color(lit ? t.working : t.foreground)) .hover((s) => s.bg(t.hover).text_color(lit ? t.working : t.foreground))
.on_click((event, cx) => { .on_click((event, cx) => {
if (this.panelJustClosed()) return;
if (enabled) action(event, cx); if (enabled) action(event, cx);
}) })
.child(glyph); .child(glyph);
@@ -3204,7 +3215,10 @@ export default class Composer extends View {
.text_color(agent ? t.muted : t.dim) .text_color(agent ? t.muted : t.dim)
.cursor_pointer() .cursor_pointer()
.hover((s) => s.bg(t.hover).text_color(t.foreground)) .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("+"); .child("+");
} }
@@ -3347,7 +3361,7 @@ export default class Composer extends View {
.cursor_pointer() .cursor_pointer()
.when(!disabled, (el) => el.hover((s) => s.opacity(0.88))) .when(!disabled, (el) => el.hover((s) => s.opacity(0.88)))
.on_click((event, cx) => { .on_click((event, cx) => {
if (!disabled) this.submit(this.value, cx); if (!disabled && !this.panelJustClosed()) this.submit(this.value, cx);
}) })
.child( .child(
div() div()
@@ -3370,7 +3384,10 @@ export default class Composer extends View {
.justify_center() .justify_center()
.cursor_pointer() .cursor_pointer()
.hover((s) => s.opacity(0.85)) .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)); .child(div().size(10).rounded(2).bg(t.background));
} }
+7 -1
View File
@@ -2,7 +2,7 @@ import test from "node:test";
import assert from "node:assert/strict"; import assert from "node:assert/strict";
import { import {
DOCK_LIMIT, LABEL_MAX, defaultLabel, normalize, isPinned, pin, unpin, remove, move, 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"; } from "../herdr/herdr-composer/mods/herdr-composer/dock.js";
const btn = (id, text, extra = {}) => ({ id, label: text, text, mode: "send", ...extra }); 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(full, { id: "n", text: "new", label: "", mode: "send" }), full);
assert.equal(add([], { id: "1", text: "x", label: "", mode: "bogus" })[0].mode, "send"); 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);
});