From 31ce7e73ce5cb604716b560fe9bb71f05c35055a Mon Sep 17 00:00:00 2001 From: Knotty Wyvern Date: Sat, 31 Oct 2026 17:33:07 -0700 Subject: [PATCH] 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. --- src/lib/layout/WorkspacePicker.svelte | 15 +++++++++++++++ tests/smoke/workspace/openAndCreate.smoke.mjs | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/lib/layout/WorkspacePicker.svelte b/src/lib/layout/WorkspacePicker.svelte index 385fea7..267b63c 100644 --- a/src/lib/layout/WorkspacePicker.svelte +++ b/src/lib/layout/WorkspacePicker.svelte @@ -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; diff --git a/tests/smoke/workspace/openAndCreate.smoke.mjs b/tests/smoke/workspace/openAndCreate.smoke.mjs index eee2845..1499b35 100644 --- a/tests/smoke/workspace/openAndCreate.smoke.mjs +++ b/tests/smoke/workspace/openAndCreate.smoke.mjs @@ -66,7 +66,12 @@ 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") }); - const opened = await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "workspace_open").length); + // 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); await page.keyboard.press("Control+o");