perf(editor): honor the Find query debounce (#34829)

* perf(editor): honor the Find query debounce

* test(editor): drop redundant Find debounce walk-count test

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-10-29 15:47:13 -07:00
committed by GitHub
co-authored by OrcaWin
parent 85ddd7aa30
commit 35c779ea36
2 changed files with 8 additions and 3 deletions
@@ -86,9 +86,10 @@ describe('live rich markdown search reuse', () => {
const { hook } = mountSearch()
act(() => hook.result.current.openSearch())
act(() => hook.result.current.searchActions.setSearchQuery('beta'))
expect(walk).toHaveBeenCalledTimes(1)
expect(walk).not.toHaveBeenCalled()
act(() => vi.advanceTimersByTime(150))
expect(hook.result.current.searchState.matchCount).toBe(2)
expect(walk).toHaveBeenCalledTimes(1)
for (let index = 0; index < 20; index++) {
act(() => hook.result.current.searchActions.setReplaceQuery(`replacement ${index}`))
act(() => hook.result.current.searchActions.moveToMatch(1))
@@ -97,6 +98,8 @@ describe('live rich markdown search reuse', () => {
act(() => hook.result.current.searchActions.closeSearch())
act(() => hook.result.current.openSearch())
act(() => hook.result.current.searchActions.setSearchQuery('beta'))
expect(walk).toHaveBeenCalledTimes(1)
act(() => vi.advanceTimersByTime(150))
expect(walk).toHaveBeenCalledTimes(2)
hook.unmount()
})
@@ -109,6 +112,7 @@ describe('live rich markdown search reuse', () => {
act(() => vi.advanceTimersByTime(150))
act(() => hook.result.current.searchActions.setSearchQuery('locked'))
expect(hook.result.current.searchState.matchCount).toBe(2)
act(() => hook.result.current.searchActions.toggleReplaceMode())
expect(hook.result.current.searchState.replaceDisabled).toBe(true)
const doc = editor.state.doc
act(() => hook.result.current.searchActions.replaceAllMatches())
@@ -89,8 +89,9 @@ export function useRichMarkdownSearch({
})
}, [editor, findMatches, isSearchOpen, matchCase, searchQuery, wholeWord])
// Derive disabled state from the same live atom guards as replacement, including during the highlight debounce.
const replaceDisabled = getLiveMatches().some((match) => match.touchesReadOnlyAtom)
// Hidden replace controls must not bypass the find debounce with a live scan.
const replaceDisabled =
isReplaceMode && getLiveMatches().some((match) => match.touchesReadOnlyAtom)
const activeMatchIndex =
!isSearchOpen || matchCount === 0