markdown_preview: Add search support to markdown preview#52502
Conversation
|
We require contributors to sign our Contributor License Agreement, and we don't have @Tahinli on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
…ch bar Hide the select-all button for searchable items that don't support multiple selections by adding a `select_all` field to `SearchOptions`. Set it to false for markdown preview and terminal. Fix a spurious right border on the close button by returning `ItemBufferKind::Singleton` from `MarkdownPreviewView::buffer_kind()`, preventing the search bar from treating the preview as a multibuffer.
|
Hi @ConradIrwin, I think I addressed the review feedbacks. I didn't do anything for rendered text feature but hoping that other issues are fixed. |
|
I'm seeing that cargo fmt check fails. Do you want me to recommit? |
|
@Tahinli please do! |
Clear stale search highlight byte ranges in `reset()` so they cannot reference old source text while a new parse and search are in progress.
@ConradIrwin Done. |
|
Thanks again for this. If you felt excited to take a pass at searching the rendered markdown instead of the source, I think that would make this feature truly excellent; but already great to have a v1 pushed. |
I will be looking at this. I'm trying to understand gpui more deeply in my free time and definitely revisit for that feature. |
|
Any chance to add search in the rendered Markdown from the Agent panel? |
I couldn't understand your wish. What do you want exactly? Also you can mention me, if you open a feature request issue or discussion. I'm happy to help. |
|
I think it'd be awesome to have cmd-f work in the agent panel (which uses markdown). It's probably a bit more complicated because that view is a stack of things that all need searching, but doesn't seem unsolvable if someone wants to take a go at it. |
Thanks @ConradIrwin for the explanation.
@Tahinli I tagged you in #39338 (comment) |
…ies#52502) Context The markdown preview had no search functionality — pressing Ctrl+F did nothing. This PR implements the SearchableItem trait for MarkdownPreviewView, enabling in-pane text search with match highlighting and navigation. Changes span four crates: - project: Added SearchQuery::search_str() — a synchronous method to search plain &str text, since the existing search() only works on BufferSnapshot. - markdown: Added search highlight storage to the Markdown entity and paint_search_highlights to MarkdownElement. Extracted the existing selection painting into a reusable paint_highlight_range helper to avoid duplicating quad-painting logic. - markdown_preview: Implemented SearchableItem with full match navigation, active match tracking, and proper SearchEvent emission matching Editor behavior. - Keymaps: Added buffer_search::Deploy bindings to the MarkdownPreview context on all three platforms. The PR hopefully Closes zed-industries#27154 How to Review 1. crates/project/src/search.rs — search_str method at the end of impl SearchQuery. Handles both Text (AhoCorasick) and Regex variants with whole-word and multiline support. 2. crates/markdown/src/markdown.rs — Three areas: - New fields and methods on Markdown struct (~line 264, 512-548) - paint_highlight_range extraction and paint_search_highlights (~line 1059-1170) - The single-line addition in Element::paint (~line 2003) 3. crates/markdown_preview/src/markdown_preview_view.rs — The main change. Focus on: - SearchEvent::MatchesInvalidated emission in schedule_markdown_update (line 384) - EventEmitter<SearchEvent> and as_searchable (lines 723, 748-754) - The SearchableItem impl (lines 779-927), especially active_match_index which computes position from old highlights to handle query changes correctly 4. Keymap files — Two lines each for Linux/Windows, one for macOS. Self-Review Checklist - [ x ] I've reviewed my own diff for quality, security, and reliability - [ x ] Unsafe blocks (if any) have justifying comments (no unsafe) - [ x ] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) (should be 😄 ) - [ - ] Tests cover the new/changed behavior (not sure) - [ - ] Performance impact has been considered and is acceptable (I'm not sure about it and it would be nice to see experienced people to test) Release Notes: - Added search support (Ctrl+F / Cmd+F) to the markdown preview --------- Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>

Context
The markdown preview had no search functionality — pressing Ctrl+F did nothing. This PR implements the SearchableItem trait for MarkdownPreviewView, enabling in-pane text search with match highlighting and navigation.
Changes span four crates:
The PR hopefully Closes #27154
How to Review
- New fields and methods on Markdown struct (~line 264, 512-548)
- paint_highlight_range extraction and paint_search_highlights (~line 1059-1170)
- The single-line addition in Element::paint (~line 2003)
- SearchEvent::MatchesInvalidated emission in schedule_markdown_update (line 384)
- EventEmitter and as_searchable (lines 723, 748-754)
- The SearchableItem impl (lines 779-927), especially active_match_index which computes position from old highlights to handle query changes correctly
Self-Review Checklist
Release Notes: