Files
sencho/frontend/src/lib/keyboard-guards.ts
T
Anso 1c5b2715b8 fix(editor): suppress global hotkeys while the code editor is focused (#1413)
Typing a single-key shortcut (a/h/u/p/b) in the compose editor opened
that shortcut's action instead of inserting the character, but only in
Chrome. The shared isInputFocused() guard recognized inputs, textareas,
and contentEditable elements; in Chromium the Monaco editor uses the
EditContext API whose focused surface is a plain focusable div, so the
guard missed it and the hotkey handlers fired. Safari falls back to a
hidden textarea, which the guard already caught.

Match any focus inside the .monaco-editor container so the guard covers
the EditContext surface, bringing Chrome to parity with Safari for both
global hotkey systems. Add a unit test for the guard.

Closes #1410
2026-06-22 19:37:01 -04:00

15 lines
665 B
TypeScript

export function isInputFocused(): boolean {
const el = document.activeElement as HTMLElement | null;
if (!el) return false;
const tag = el.tagName;
if (tag === 'INPUT' || tag === 'TEXTAREA' || el.isContentEditable) return true;
// Monaco's EditContext surface (Chromium) is a plain focusable <div>, not a textarea or
// contentEditable element, so the checks above miss it. Treat any focus inside the editor
// container as input focus, matching the textarea fallback other browsers already get.
return !!el.closest('.monaco-editor');
}
export function isPaletteOpen(): boolean {
return !!document.querySelector('[role="dialog"] [cmdk-root]');
}