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.
This commit is contained in:
David Montero 2026-07-18 02:41:04 +02:00 committed by David Montero Crespo
parent 5218f7314b
commit 2e5ac20eba
1 changed files with 8 additions and 1 deletions

View File

@ -37,7 +37,14 @@ function isTypingTarget(target: EventTarget | null): boolean {
const el = target as HTMLElement | null; const el = target as HTMLElement | null;
if (!el || !el.tagName) return false; if (!el || !el.tagName) return false;
const tag = el.tagName; 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 <div> (.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 { export function useButtonKeyBindings(components: BoundComponent[]): void {