From 2b89d4f3057c7ea992094598a4c437b1a6d2b6d9 Mon Sep 17 00:00:00 2001 From: JustJ01 Date: Tue, 17 Feb 2026 09:11:58 +0530 Subject: [PATCH] fix enter key to confirm new document dailog --- .../src/components/floating-menus/Dialog.svelte | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/frontend/src/components/floating-menus/Dialog.svelte b/frontend/src/components/floating-menus/Dialog.svelte index ce06b22626..17196fc591 100644 --- a/frontend/src/components/floating-menus/Dialog.svelte +++ b/frontend/src/components/floating-menus/Dialog.svelte @@ -18,10 +18,26 @@ let self: FloatingMenu | undefined; + function onDialogContentKeyDown(e: KeyboardEvent) { + if ($dialog.title !== "New Document" || e.isComposing || e.key !== "Enter") return; + if (!(e.target instanceof HTMLInputElement) || !e.target.hasAttribute("data-input-element")) return; + if (!self?.div?.()?.contains(e.target)) return; + + const emphasizedOrFirstButton = (self?.div?.()?.querySelector("[data-emphasized]") || self?.div?.()?.querySelector("[data-text-button]") || undefined) as HTMLButtonElement | undefined; + if (!emphasizedOrFirstButton || emphasizedOrFirstButton.dataset.disabled !== undefined) return; + + e.preventDefault(); + setTimeout(() => emphasizedOrFirstButton.click(), 0); + } + onMount(() => { + window.addEventListener("keydown", onDialogContentKeyDown, true); + // Focus the button which is marked as emphasized, or otherwise the first button, in the popup const emphasizedOrFirstButton = (self?.div?.()?.querySelector("[data-emphasized]") || self?.div?.()?.querySelector("[data-text-button]") || undefined) as HTMLButtonElement | undefined; emphasizedOrFirstButton?.focus(); + + return () => window.removeEventListener("keydown", onDialogContentKeyDown, true); });