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:
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" },
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user