markdown: Fix search highlights hiding text with opaque theme colors (#64788)

## Summary

Closes https://github.com/zed-industries/zed/issues/64727

**Problem:** In the Markdown Preview (`cmd+shift+v`), when searching
with `cmd+f` while using a theme with an opaque
`search.match_background`, such as Dracula Solid (`#287d3eff`), the
highlight covers the matched word, making the text unreadable.

**Cause:** In `crates/markdown`, the highlights (search and selection)
were rendered after the glyphs, meaning they were drawn on top of the
text. In the editor, they are rendered underneath the text.

**Fix:** Render the highlights before the text. This change also applies
to search in the agent panel, which uses the same code.

<img width="1280" height="440" alt="md_after_default"
src="https://github.com/user-attachments/assets/d617b897-7f05-4f29-a266-b41d33ca81c2"
/>
<img width="1280" height="440" alt="md_before_default"
src="https://github.com/user-attachments/assets/42e56af6-2a58-4b48-8ebf-1041608cf4bc"
/>
<img width="1280" height="440" alt="md_after_dracula"
src="https://github.com/user-attachments/assets/c52a875b-04d3-40e9-b020-d1f44c2bf24c"
/>
<img width="1280" height="440" alt="md_before_dracula"
src="https://github.com/user-attachments/assets/8922402b-ffc9-479c-abb1-fcb9e481864d"
/>


## Testing

- Added `test_search_highlights_are_painted_below_text`, which fails
without the fix and passes with it.
- `cargo test -p markdown -p markdown_preview` passes.
- Manually tested on macOS with the Dracula Solid theme: open a `.md`
file → `cmd-shift-v` → `cmd-f` → search for a word. The matched text now
renders on top of the highlight instead of being hidden by it.
- Tested on macOS only.

## Self-review

- [x] I've reviewed my diff for quality, security, reliability, and
performance.
- [x] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist).
- [x] Tests cover the new or changed behavior.

Release Notes:

- Fixed search highlights in Markdown Preview hiding the matched text
when the theme uses opaque highlight colors
- [GPUI] Added `TextLayout::paint_background` and
`TextLayout::paint_foreground` to paint a text's run backgrounds and
glyphs separately

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Kirill Bulatov <kirill@zed.dev>
bda9c0bd43Fabrício Lima committed on 9/26/2026, 6:58:38 PM· committed by GitHubparent70e686c
3 files changedLine totals unavailable