fix(app): R1 Escape layers with the page focused, twin keyboard framing, « Plus » field guard

This commit is contained in:
bchanot committed 2026-11-12 13:42:00 +01:00
1 parent 90a5e7aa35
commit 132756eecd
7 files changed
+130 -8

No files matched your search

+7 -2
View File
@@ -7,6 +7,7 @@ import {
isTextField,
visibleElement,
} from '@/editor/focusRequest'
import { ReferencesOpenContext } from '@/editor/editingContext'
import { CANVAS_BOX } from '@/editor/useEditorNavigation'
import { useT } from '@/i18n/useT'
@@ -54,7 +55,7 @@ export function useDeselect(id: string | null, clear: () => void) {
}
/** Whether a key event happened in the editor workspace (or with nothing focused). */
function inWorkspace(target: EventTarget | null): boolean {
export function inWorkspace(target: EventTarget | null): boolean {
if (target === document.body) return true
return (
target instanceof Element &&
@@ -79,6 +80,9 @@ export function useEscapeDeselect(
if (event.key !== 'Escape' || event.defaultPrevented) return
if (event.isComposing || isTextField(event.target)) return
if (!inWorkspace(event.target)) return
// A keydown aimed at body never reaches the React root: the layers above (a modal,
// the phone drawer) are checked here.
if (document.querySelector('dialog[open]')) return
if (handler.current(event)) event.preventDefault()
}
document.addEventListener('keydown', onKey)
@@ -98,7 +102,8 @@ export function useSelectionEscape(
) {
const asideRef = useRef<HTMLElement>(null)
const deselect = useDeselect(id, clear)
useEscapeDeselect(active, (event) =>
const referencesOpen = useContext(ReferencesOpenContext)
useEscapeDeselect(active && !referencesOpen, (event) =>
deselect.byKey(asideRef.current?.contains(event.target as Node) ?? false),
)
return { asideRef, byDrawing: deselect.byDrawing }