← All posts

Your search says 2 matches. You can only see 1.

By ·

Search a README in Zed's markdown preview for a common word and the count lies to you. It says 2 matches when only 1 is on screen. Hit enter to jump to the second one and nothing appears to happen.

Why it happens

The preview renders markdown, but search ran against the raw markdown source. Every piece of syntax that never becomes visible text is still searchable:

  • Link destinations — in [label](url), only label renders, but url is still matched
  • Images, including both alt text and destination
  • Link reference definitions, which pulldown-cmark consumes without emitting any event

Badge-heavy READMEs make this much worse. Every badge URL contributes words like github, build, main, and svg that the reader never sees.

The fix

Track which source ranges produce no on-screen text, then filter matches against them. The ranges are returned sorted and disjoint, so the preview can binary search rather than scan.

There was a second, subtler bug underneath. Search results derive from the parsed markdown, and the parse happens in the background — so results could be computed against a stale parse. MatchesInvalidated now fires once the parse lands.

Testing

Eight new tests cover link destinations, reference definitions, standalone images, linked images, images between link text, parse-in-flight, and match-order independence.

Merged as zed-industries/zed#62280.