Close the workspace menu on a second click of its button

The menu is an automatic popover. A press on the button closed the open
menu, and the click that followed opened it again. The picker now
records an open menu when the press starts on the button. The click
then leaves the menu closed.

The workspace smoke test clicks the button two times. Card 53db89fc.
This commit is contained in:
Knotty Wyvern
2026-10-31 17:33:07 -07:00
parent 8e2df5544a
commit 31ce7e73ce
2 changed files with 21 additions and 1 deletions
+15
View File
@@ -23,9 +23,24 @@
const folderName = (path: string) => path.replace(/[\\/]+$/, "").split(/[\\/]/).pop() || path;
const removeTooltip = (node: HTMLElement) => ({ destroy: attachTooltip(node, () => tr("Remove from recent workspaces")) });
const destination = $derived(parent ? `${parent.replace(/[\\/]+$/, "")}${parent.includes("\\") ? "\\" : "/"}${name.trim()}` : $t("Choose where to create your workspace."));
// A press on the anchor closes the open menu before the click. Then the click must not open it again.
let pressedOpen = false;
$effect(() => {
const target = anchor;
if (!target) return;
const press = () => {
pressedOpen = menu.matches(":popover-open");
// The click comes in the same task as the release. A drag away from the anchor gives no click.
if (pressedOpen) window.addEventListener("pointerup", () => setTimeout(() => { pressedOpen = false; }), { once: true });
};
target.addEventListener("pointerdown", press);
return () => target.removeEventListener("pointerdown", press);
});
export async function show() {
if (busy || creating) return;
if (pressedOpen) { pressedOpen = false; return; }
if (menu.matches(":popover-open")) { menu.hidePopover(); return; }
returnFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
error = ""; loading = true;
@@ -66,6 +66,11 @@ await runSmoke("workspace/openAndCreate", async ({ page }) => {
assert.equal(await menu.locator('[aria-current="true"]').count(), 1);
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "plugin:dialog|open").length), 0);
await page.screenshot({ path: path.join(output, "workspaces-menu.png") });
// A second click on the switcher closes the menu. It does not open the menu again.
await trigger.click();
await menu.waitFor({ state: "hidden", timeout: 2000 });
await trigger.click();
await menu.getByText("D:\\Writing\\Notes", { exact: true }).waitFor();
const opened =await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "workspace_open").length);
await menu.getByRole("button").filter({ hasText: "Current" }).click();
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "workspace_open").length), opened);