Skip to content

fix(superdoc): restore find input focus after match navigation (SD-3045)#3240

Open
tupizz wants to merge 1 commit into
mainfrom
tadeu/sd-3045-find-replace-focus-loss
Open

fix(superdoc): restore find input focus after match navigation (SD-3045)#3240
tupizz wants to merge 1 commit into
mainfrom
tadeu/sd-3045-find-replace-focus-loss

Conversation

@tupizz
Copy link
Copy Markdown
Contributor

@tupizz tupizz commented May 11, 2026

Summary

Pressing Enter in the built-in find/replace input used to advance to the next match once, then drop focus into the ProseMirror editor. Subsequent Enter keystrokes were swallowed by the editor (splitting paragraphs at the match position, invalidating the search session, and resetting the active match index back to zero), forcing the user to click back into the input between every navigation. The "alternating jump back to page 1" symptom in the ticket title is a downstream effect of the same focus steal.

Root cause: the Search extension's goToSearchResult calls editor.view.focus() so its newly-set selection is visible β€” by design when called programmatically β€” but FindReplaceSurface.vue's Enter handler did not restore focus afterwards.

Fix: re-focus the find input synchronously after goNext / goPrev returns. The handler already calls e.preventDefault(), so once focus stays on the input the editor never sees the keystroke.

The change is local to FindReplaceSurface.vue β€” the underlying Search command behaviour (used by the dev sidebar and the public SuperDoc.goToSearchResult API) is unchanged.

Test plan

  • New FindReplaceSurface.test.js covers: Enter keeps focus when goNext synchronously steals focus elsewhere; Shift+Enter / goPrev does the same; Enter's default is still prevented.
  • All 962 superdoc package tests pass.
  • Browser reproduction on the dev app: 5 consecutive Enters advanced 2/16 β†’ 7/16 with focus retained, 3 Shift+Enters returned to 4/16.

The Search extension's goToSearchResult calls editor.view.focus() so the
new selection is visible. When the user pressed Enter in the built-in find
input, the synchronous focus steal blurred the input β€” subsequent Enter
keystrokes were swallowed by the ProseMirror editor, splitting paragraphs
at the match position, invalidating the search session, and resetting the
active match index. The user had to click back into the input between
every navigation.

Re-focus the find input synchronously after goNext / goPrev so repeated
Enter / Shift+Enter keeps advancing through matches and the editor never
receives the keystroke.
@tupizz tupizz requested a review from a team as a code owner May 11, 2026 23:01
@linear
Copy link
Copy Markdown

linear Bot commented May 11, 2026

SD-3045

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.

πŸ“’ Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants