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");