fix: dock menu opens on the first right click after a command

Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
FactorandOvis Fast committed 2026-11-19 16:12:38 +01:00
1 parent 52d2259060
commit 3c65a4f577
3 files changed
+61 -7

No files matched your search

@@ -229,3 +229,19 @@ export function starMenu({ text, pinned }) {
},
];
}
/**
* The menu that is open after a `Popover` said it opened or closed.
*
* Opening always opens that menu (the one before it, if any, is replaced).
* Closing only closes the menu it is about: a late "closed" of a menu that
* another one has replaced must leave the new one open.
*
* @param {{kind: string, id: string}|null} current
* @param {{kind: string, id: string, open: boolean}} change
* @returns {{kind: string, id: string}|null}
*/
export function menuTransition(current, { kind, id, open }) {
if (open) return { kind, id };
return current && current.kind === kind && current.id === id ? null : current;
}
@@ -79,6 +79,7 @@ import {
move as moveButton,
rename as renameButton,
toggleMode,
menuTransition,
DOCK_LIMIT,
} from "./dock.js";
import {
@@ -267,6 +268,7 @@ export default class Composer extends View {
// The right-click menu that is open: { kind: "dock"|"row"|"star", id } or
// null. `renaming` is the id of the button whose name is being edited.
this.contextMenu = null;
this.menuOpenedAt = 0;
this.renaming = null;
this.renameStartedAt = 0;
// Esc that an overlay (menu, name edit) took must not reach the agent a
@@ -1093,16 +1095,32 @@ 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) {
if (open) {
this.contextMenu = { kind, id };
} else if (this.contextMenu && this.contextMenu.kind === kind && this.contextMenu.id === id) {
this.contextMenu = null;
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.
if (!open && this.contextMenu && now - this.menuOpenedAt < 150) {
cx.notify();
return;
}
const before = this.contextMenu;
this.contextMenu = menuTransition(before, { kind, id, open });
if (open) this.menuOpenedAt = now;
else if (before && !this.contextMenu) {
// The Popover took Esc itself: the same press must not reach the agent.
this.escSwallowUntil = Date.now() + 80;
this.escSwallowUntil = now + 80;
}
cx.notify();
}
/**
* A right press on a button of the dock or on the star opens its menu at
* once, whatever the Popover makes of the press: the first right click after
* a command or a click elsewhere always opens the menu.
*/
openMenuByPress(kind, id, cx) {
this.popoverChanged(kind, id, true, cx);
}
/** A command of the menu that is open was chosen. */
menuCommand(command, cx) {
const menu = this.contextMenu;
@@ -2872,6 +2890,7 @@ export default class Composer extends View {
// Right click: the menu of the button, anchored to it.
const open = this.contextMenu?.kind === "dock" && this.contextMenu.id === button.id;
el = el.on_mouse_down("right", (event, cx) => this.openMenuByPress("dock", button.id, cx));
return Popover.new(`dock-menu-${button.id}`)
.mouse_button("right")
.anchor("bottom_left")
@@ -2927,7 +2946,7 @@ export default class Composer extends View {
* opens the menu that pins the text of the field to the dock.
*/
renderStar(t, active) {
const icon = this.renderIcon(
let icon = this.renderIcon(
t,
"composer-star",
isFavorite(this.favorites, this.value) ? "★" : "☆",
@@ -2938,6 +2957,7 @@ export default class Composer extends View {
if (!active) return icon;
const open = this.contextMenu?.kind === "star";
icon = icon.on_mouse_down("right", (event, cx) => this.openMenuByPress("star", "star", cx));
return Popover.new("composer-star-menu")
.mouse_button("right")
.anchor("bottom_left")