Repository navigation
feat(document): search the rendered text with /, then n and N - #174
Merged
Merged
Conversation
backnotprop
force-pushed
the
feat/doc-search
branch
from
November 20, 2026 02:51
b1d7a75 to
7fe3532
Compare
A one-line prompt in the footer searches the open document as it is typed: every match is highlighted, the cursor lands on the first at or after it, and the footer counts them. Enter keeps the search, Esc puts the view back; n and N step through matches with wraparound, and a second Esc clears the highlights. Matching runs over the rendered lines before wrapping, so a match can cross a soft wrap, and each match maps back to its source range through the existing source map, which is what the screen's cells carry: the highlight finds its cells in wrapped rows, table cells and list items. Smartcase, plain text. The index is built once per document on the first /, so a keystroke costs one search and no relayout. New keys search, next-match and previous-match (/, n, N) are live only in the document and yield to an older config that took those keys. New colour roles search and search-current keep matches apart from notes. --bench times the index and a few searches. Closes #137
backnotprop
force-pushed
the
feat/doc-search
branch
from
November 20, 2026 04:24
7fe3532 to
725929b
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds text search to the Markdown document screen.
What it does
/opens a one-line prompt in the footer. Each keystroke highlights every match and moves the cursor to the first match at or after where/was pressed. The footer shows the count (3/17).Enterkeeps the search and closes the prompt.Esccloses it and restores the view, the cursor, the selected block and any earlier search.n/Ngo to the next / previous match, wrapping at both ends. The footer says "search wrapped to the top/bottom".Escpeels one layer at a time: a waiting selection, then the search highlights, then quit. An empty search also clears the highlights.vselects from it.How matching works
The search runs over the rendered lines before wrapping (
DocLayout::rendered_lines). A soft wrap never enters the searched text, so a match can run across one. Each match maps back to a source range through the existing source map. The screen's cells carry the same source offsets, so the highlight finds its cells in wrapped rows, wrapped table cells and list items. A cell with no source byte that sits between two cells of the same match is filled in, for example the space a soft break became. A query does not cross a hard line break, a list item or a table row. The index is built once per document, on the first/, and it does not depend on width. A long document that is still being laid out in the background (#166) is finished first, so the search covers all of it. A keystroke costs one search and no relayout.Keys
New actions
search(/),next-match(n) andprevious-match(N). They are live only in the document pane, where none of those keys was bound.n/Nkeep their meanings in the quit and clear-all questions (no) and in the code review (next-file/previous-file), because those contexts never read the same keypress. The new actions are inLATE, so a config that already gave these keys to another action still loads, and the search key it collides with is left unbound. Example:down = ["n", "Down"]. The footer hints name the keys you have bound. The README key table and the crate README list the new actions. The?help screen exists only in the code review, which has no search, so the new keys are not listed there.Colours
New
[colors]rolessearch(all matches, dark 24 / light 117) andsearch-current(the current match, dark 208 / light 214 with black text). They work likecursorandselection. A test checks that neither role uses an annotation tint, the block bar or the cursor background.Performance (
--bench samples/big.md, release, 2.5 MB)e240,156 matches in 5.3 ms,th1.8 ms,the1.6 ms,plugin0.9 ms, no match 0.6 msKnown limit: a match in the part of a long code line that is clipped off screen has no cell. It is counted, and the cursor goes to the first row of its block.
Tests: unit tests for matching (smartcase, plain text, markup, soft wrap, soft break, list item, wrapped table cell, decoration only, no match, wraparound, a non-length-preserving lower case). Screen tests in a
TestBackendcover the prompt, the count,n/N, the Esc layers, an empty search, no match, a wrap-spanning highlight withvfrom the match, a waiting selection and an annotation tint left alone, rebinding, folder mode, highlights that follow</>andzreflows, and matches in coloured code (also in a code block nested in a list) that keep their syntax colour under the search background. Key tests cover defaults, other contexts, and old configs.Closes #137