From 2e5ac20eba5cfdfa5fb32cfef5c9d4cbf7fdc624 Mon Sep 17 00:00:00 2001 From: David Montero Date: Sat, 18 Jul 2026 02:41:04 +0200 Subject: [PATCH] fix(simulator): don't fire key-bound buttons while typing in Monaco Monaco's focus sink is a plain div (.native-edit-context under the EditContext API), neither an input tag nor contentEditable, so the typing guard missed it and a mapped letter typed into the code editor pressed the button. Treat any keydown originating inside .monaco-editor as typing. --- frontend/src/hooks/useButtonKeyBindings.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/src/hooks/useButtonKeyBindings.ts b/frontend/src/hooks/useButtonKeyBindings.ts index e3046710..c55932e2 100644 --- a/frontend/src/hooks/useButtonKeyBindings.ts +++ b/frontend/src/hooks/useButtonKeyBindings.ts @@ -37,7 +37,14 @@ function isTypingTarget(target: EventTarget | null): boolean { const el = target as HTMLElement | null; if (!el || !el.tagName) return false; const tag = el.tagName; - return tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT' || el.isContentEditable; + if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT' || el.isContentEditable) { + return true; + } + // Monaco's focus sink is a plain
(.native-edit-context with the + // EditContext API, .inputarea textarea otherwise) — neither an input tag + // nor contentEditable, so the checks above miss it. Treat any keydown + // originating inside the editor widget as typing. + return typeof el.closest === 'function' && el.closest('.monaco-editor') !== null; } export function useButtonKeyBindings(components: BoundComponent[]): void {