Repository navigation
Markdown preview visible find matches - #62280
SomeoneToIgnore merged 4 commits into
Conversation
Extend the non-rendered source ranges beyond link destinations so search matches only text the reader can actually see: - Images render as an image, so neither the alt text nor the destination is on screen. Skipping their events also keeps alt text from carving a hole out of an enclosing link's non-rendered span. - Link reference definitions are consumed by the parser and never appear in any event range, so collect their spans from pulldown-cmark. Search results are derived from the parsed markdown, which lags the source while a background parse is in flight. Track that and emit MatchesInvalidated once it lands, so stale matches are not left behind. The returned ranges are now sorted and disjoint, which lets the preview binary search them instead of carrying a cursor across matches. That drops an undocumented dependency on SearchQuery::search_str returning matches in ascending order.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0b579dd120
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| .reference_definitions() | ||
| .iter() | ||
| .map(|(_, definition)| definition.span.clone()) |
There was a problem hiding this comment.
Preserve every duplicate reference-definition span
When a document contains multiple definitions with the same normalized label (for example, two [foo]: ... lines, or labels differing only by case), reference_definitions() exposes the selected definitions keyed by label, so iterating this map retains only one span. CommonMark still consumes every duplicate definition without rendering it, leaving the omitted definitions searchable as phantom matches. Collect the consumed definition spans independently of the deduplicated lookup map.
Useful? React with 👍 / 👎.
|
/autofix |
# Objective Search in the markdown preview matches against the raw markdown source, including text that never renders. Searching a README for a common word reports more matches than are visible: the count says 2 when only 1 is on screen, and navigating to the phantom match appears to do nothing. Badge-heavy READMEs make this worse, since every badge URL contributes searchable words (`github`, `build`, `main`, `svg`) that the reader never sees. ## Solution Track which source ranges produce no on-screen text and filter matches against them: - Link destinations (`[label](url)`, where only `label` renders) - Images, including alt text and destination, since an image renders as an image - Link reference definitions, which `pulldown-cmark` consumes and never emits events for Ranges are returned sorted and disjoint so the preview can binary search them. Search results also derive from the parsed markdown, which lags the source during a background parse, so `MatchesInvalidated` now fires once the parse lands. ## Testing `cargo test -p markdown -p markdown_preview`. Eight new tests cover link destinations, reference definitions, standalone images, linked images, images between link text, parse-in-flight, and match-order independence. Note: `follow_preview_serialized_path_updates_when_followed_editor_changes` fails on `main` independently of this change (sqlite `FOREIGN KEY constraint failed` in `save_preview`, passes in isolation). ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [ ] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable ## Showcase Markdown preview search on the same document, installed Zed versus this branch: Before: <img width="1090" height="1235" alt="warya_wayne_zed_fix_miscounted_search_in_Markdown_preview_current" src="https://github.com/user-attachments/assets/d2e59e12-b43e-4fea-ac9c-12631845653b" /> After: <img width="1090" height="1235" alt="warya_wayne_zed_fix_miscounted_search_in_Markdown_preview_new" src="https://github.com/user-attachments/assets/9f681fa4-f141-41c9-af9f-675cf3a2f0bd" /> --- Release Notes: - Fixed markdown preview search matching text that isn't rendered, such as link and image destinations --------- Co-authored-by: zed-zippy[bot] <234243425+zed-zippy[bot]@users.noreply.github.com>
# Objective Search in the markdown preview matches against the raw markdown source, including text that never renders. Searching a README for a common word reports more matches than are visible: the count says 2 when only 1 is on screen, and navigating to the phantom match appears to do nothing. Badge-heavy READMEs make this worse, since every badge URL contributes searchable words (`github`, `build`, `main`, `svg`) that the reader never sees. ## Solution Track which source ranges produce no on-screen text and filter matches against them: - Link destinations (`[label](url)`, where only `label` renders) - Images, including alt text and destination, since an image renders as an image - Link reference definitions, which `pulldown-cmark` consumes and never emits events for Ranges are returned sorted and disjoint so the preview can binary search them. Search results also derive from the parsed markdown, which lags the source during a background parse, so `MatchesInvalidated` now fires once the parse lands. ## Testing `cargo test -p markdown -p markdown_preview`. Eight new tests cover link destinations, reference definitions, standalone images, linked images, images between link text, parse-in-flight, and match-order independence. Note: `follow_preview_serialized_path_updates_when_followed_editor_changes` fails on `main` independently of this change (sqlite `FOREIGN KEY constraint failed` in `save_preview`, passes in isolation). ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [ ] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable ## Showcase Markdown preview search on the same document, installed Zed versus this branch: Before: <img width="1090" height="1235" alt="warya_wayne_zed_fix_miscounted_search_in_Markdown_preview_current" src="https://github.com/user-attachments/assets/d2e59e12-b43e-4fea-ac9c-12631845653b" /> After: <img width="1090" height="1235" alt="warya_wayne_zed_fix_miscounted_search_in_Markdown_preview_new" src="https://github.com/user-attachments/assets/9f681fa4-f141-41c9-af9f-675cf3a2f0bd" /> --- Release Notes: - Fixed markdown preview search matching text that isn't rendered, such as link and image destinations --------- Co-authored-by: zed-zippy[bot] <234243425+zed-zippy[bot]@users.noreply.github.com>
Objective
Search in the markdown preview matches against the raw markdown source, including text that never renders. Searching a README for a common word reports more matches than are visible: the count says 2 when only 1 is on screen, and navigating to the phantom match appears to do nothing. Badge-heavy READMEs make this worse, since every badge URL contributes searchable words (
github,build,main,svg) that the reader never sees.Solution
Track which source ranges produce no on-screen text and filter matches against them:
[label](url), where onlylabelrenders)pulldown-cmarkconsumes and never emits events forRanges are returned sorted and disjoint so the preview can binary search them. Search results also derive from the parsed markdown, which lags the source during a background parse, so
MatchesInvalidatednow fires once the parse lands.Testing
cargo test -p markdown -p markdown_preview. Eight new tests cover link destinations, reference definitions, standalone images, linked images, images between link text, parse-in-flight, and match-order independence.Note:
follow_preview_serialized_path_updates_when_followed_editor_changesfails onmainindependently of this change (sqliteFOREIGN KEY constraint failedinsave_preview, passes in isolation).Self-Review Checklist:
Showcase
Markdown preview search on the same document, installed Zed versus this branch:
Before:

After:

Release Notes: