fix(editor): keep composition-owned Escape inside Find (#34969)

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-10-29 15:56:33 -07:00
committed by GitHub
co-authored by OrcaWin
parent 2e5711fcaa
commit e7e3e568e7
2 changed files with 39 additions and 1 deletions
@@ -91,6 +91,43 @@ afterEach(() => {
})
describe('rich Markdown search adversarial interactions', () => {
it.each([{ isComposing: true }, { keyCode: 229 }])(
'keeps Find open when Escape belongs to the IME (%o)',
(init) => {
const { hook, input, query } = mountSearch()
query('beta')
const event = new KeyboardEvent('keydown', {
key: 'Escape',
bubbles: true,
cancelable: true,
...init
})
act(() => input.dispatchEvent(event))
expect(hook.result.current.searchState.isSearchOpen).toBe(true)
expect(hook.result.current.searchState.searchQuery).toBe('beta')
expect(document.activeElement).toBe(input)
expect(event.defaultPrevented).toBe(false)
}
)
it('still closes Find and returns to the editor on plain Escape', () => {
const { hook, editor, input } = mountSearch()
const event = new KeyboardEvent('keydown', {
key: 'Escape',
bubbles: true,
cancelable: true
})
act(() => input.dispatchEvent(event))
act(() => vi.runOnlyPendingTimers())
expect(hook.result.current.searchState.isSearchOpen).toBe(false)
expect(document.activeElement).toBe(editor.view.dom)
expect(event.defaultPrevented).toBe(true)
})
it('does not revive a delayed search after a document click and another control focus', () => {
const { editor, hook, otherControl, query, documentCaret, scrollTo } = mountSearch()
query('beta')
@@ -15,6 +15,7 @@ import {
import { createRichMarkdownSearchMatchesCache } from './rich-markdown-search-matches-cache'
import { useRichMarkdownSearchHighlights } from './useRichMarkdownSearchHighlights'
import { addAppKeyListener, removeAppKeyListener } from '@/lib/app-keyboard-router'
import { isImeOwnedKeyboardEvent } from '@/lib/ime-composition-keyboard-event'
export function useRichMarkdownSearch({
editor,
@@ -269,7 +270,7 @@ export function useRichMarkdownSearch({
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent): void => {
const root = rootRef.current
if (!root) {
if (!root || isImeOwnedKeyboardEvent(event)) {
return
}