feat: search from selected text and copy document as Markdown - #231
feat: search from selected text and copy document as Markdown#231junglesub wants to merge 1 commit into
Conversation
|
Thanks for this — the find half is a real gap, and it's landing with you as the author in #586. The copy half I'm dropping; reasoning for both below. Taking: seeding the find bar from the selectionReworked before landing, on three points. The editor half needs no code. Monaco's The preview half was off in the commonest case. "Start from the selected occurrence" is not landing. That part carried ~110 of the 120 lines: the What's left in Not taking: Copy as MarkdownIn reading mode, That is fixable in a line. But it means the feature carries a standing contract with the large-file state machine in order to save three keystrokes, and "Copy" that ignores your selection is a surprise every user gets to have once. Not a good trade for a reader that advertises itself as restrained. One note for next timeNew chords belong in Thanks again — the find change is the better half and it's yours. |
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: junglesub <junglesubmarine@gmail.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
|
Thank you so much for taking the time to think through the PR in such depth and for explaining the reasoning behind your decisions. I originally made these changes for my own use and decided to share them, but your response helped me understand how differently you have to think about a change when looking at it from the perspective of a larger project, especially the trade-offs between a feature's value, complexity, and long-term maintenance. Thanks again for the great project and for giving me an opportunity to learn and grow through contributing to it. |
Summary
Adds selected-text search and a command to copy the current document's full Markdown source.
Changes
Ctrl/Cmd+Fwith the selected text in the editor and rendered previewCtrl/Cmd+Shift+Cas the copy Markdown shortcutCopy As Markdown (Ctrl/Cmd + Shift + C)
Find selected text (Ctrl/Cmd+F)
Testing
pnpm run test:workflowspnpm run check