Skip to content

feat(find): open the preview find bar on the selected text - #586

Merged
PathGao merged 1 commit into
masterfrom
feat/find-selected-text
Aug 11, 2026
Merged

feat(find): open the preview find bar on the selected text#586
PathGao merged 1 commit into
masterfrom
feat/find-selected-text

Conversation

@PathGao

@PathGao PathGao commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Reworked from #231, which bundled this with a Copy-as-Markdown command. The copy half is not landing (reasoning in that thread); this is the half that closes a real gap. The commit keeps @junglesub as the author.

What changes

Select a word in the rendered preview, press Cmd/Ctrl+F, and the bar opens with that word already in it.

The editor pane has behaved this way for as long as it has used Monaco — seedSearchStringFromSelection defaults to seeding — so the two panes disagreed about the same keystroke, and the preview was the one that made you retype the word you were already pointing at.

Decisions

The seed is selection.toString(), not the text of one node. A selection crossing **bold**, a link or inline code spans several text nodes, and those are the words a reader is most likely to have highlighted. Reading a single node would have left the feature off in the commonest case.

Single-line selections only — Monaco's own rule in the other pane, so the app agrees with itself about one keystroke instead of growing a second rule. A paragraph in the search box matches nothing and buries the query the user was about to type.

Nothing to seed leaves the previous query alone rather than clearing it: a caret with nothing selected, a selection in a modal or the tab strip, whitespace. A repeated Cmd/Ctrl+F still just re-focuses and re-selects the box (#559).

setQuery is the assignment and nothing else. The existing query effect schedules the search, so a seed goes through the same debounce and the same not-yet-open guard as typing. applyHighlights and the scroll-restore path are untouched.

Not included: starting from the selected occurrence rather than the first match. #231 spent ~110 lines on it — a pendingActiveRange / getRangeMatchIndex / getClosestMarkIndex fallback chain, an untrack change to the sanitizedHtml effect, and an extra reapply() in the render path — inside a tree walk that mutates the nodes it is walking. It can come back on its own merits.

Testing

npm test — 977 pass. npm run check — clean.

The decision of whether to seed is the whole feature, so it lives in src/lib/utils/findSeed.ts as a pure function the test imports and runs, plus one source-shape line for the wiring (a pure function nothing calls is dead code). Checked by mutation: dropping the single-line rule fails it, and so does dropping the containment guard.

Manually verified on macOS with a debug build: selecting across bold and inline code, selecting in the tab strip, repeated Cmd+F with no selection, and split view.

🤖 Generated with Claude Code

Reworked from #231.

Select a word in the rendered document, press Cmd/Ctrl+F, and the bar opens
with that word already in it. The editor pane has done this for as long as it
has used Monaco -- `seedSearchStringFromSelection` defaults to seeding -- so
the two panes disagreed about the same keystroke, and the preview was the one
that made you type the word you were already pointing at.

The seed is `selection.toString()`, not the text of a single node. A selection
that crosses `**bold**`, a link or inline code spans several nodes, and those
are the words a reader is most likely to have highlighted; reading one node
would have left the feature off in the commonest case.

Single-line selections only, which is Monaco's rule in the other pane. A
paragraph in the search box matches nothing and buries the query the user was
about to type. Everything else is left alone rather than cleared: a caret with
nothing selected, a selection in a modal or the tab strip, whitespace. A
repeated Cmd/Ctrl+F with no selection still just re-focuses the box (#559).

`setQuery` is the assignment and nothing else -- the existing `query` effect
schedules the search, so a seed goes through the same debounce and the same
not-yet-open guard as typing does, and the highlight walk is untouched.

The decision of whether to seed is the whole feature, so it is a pure function
in `utils/findSeed.ts` that the test imports and runs -- the behaviour kind
AGENTS.md asks for, rather than a harness that lifts it back out of the
component. One source-shape line covers the wiring, since a pure function
nothing calls is dead code. Checked by mutation: dropping the single-line rule
or the containment guard each fails it. 977 tests pass, svelte-check clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@PathGao
PathGao merged commit 3cef924 into master Aug 11, 2026
4 checks passed
@PathGao
PathGao deleted the feat/find-selected-text branch August 11, 2026 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants