Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/platform/keybindings/keybindingService.escape.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ describe('keybindingService - Escape key handling', () => {
}
)

it('does not throw when Escape fires with a non-Element target (e.g. document, in Safari when nothing has focus)', async () => {
const event = createKeyboardEvent('Escape', {
target: document as unknown as Element
})

await expect(keybindingService.keybindHandler(event)).resolves.not.toThrow()

expect(useCommandStore().execute).toHaveBeenCalledWith(
'Comfy.Graph.ExitSubgraph'
)
})

describe('registered Escape override', () => {
it('suppresses ExitSubgraph when a registered override handles the event', async () => {
const override = vi.fn().mockReturnValue(true)
Expand Down
4 changes: 4 additions & 0 deletions src/platform/keybindings/keybindingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ export function useKeybindingService() {

const target = event.composedPath()[0] as HTMLElement
// Let the active menu own Escape without also triggering the global shortcut.
// `target` is usually the focused element, but when nothing has focus some
// browsers (e.g. Safari) target the event at `document` instead of
// `document.body`, which has no `closest` method.
if (
event.key === 'Escape' &&
target instanceof Element &&
target.closest('[role="menu"], [role="menubar"]')
) {
return
Expand Down
Loading