mirror of
https://github.com/zed-industries/zed.git
synced 2026-05-26 15:44:20 +00:00
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 https://github.com/zed-industries/zed/issues/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> |
||
|---|---|---|
| .. | ||
| src | ||
| Cargo.toml | ||
| LICENSE-GPL | ||