markdown: Optimize `paint_search_highlights` (#59473)

Follow up to #52502

This fixes a severe hang in the markdown preview when searching for text
caused by `paint_search_highlights`. We were iterating over all lines
for each highlight, and for each highlight we called
`layout.line_layout_for_index` which internally would iterate over all
the lines of the text layout.

With this optimisation we paint all highlights in one pass. We sort the
highlight ranges, iterate through the lines and only access
`WrappedLineSegments` when we actually have a highlight in that line.

E.g. if you copy this text
(https://gist.github.com/bennetbo/e313f3023da9fec42e090177a5373152) into
the editor, open the markdown preview and search for `codex` Zed Nightly
will completely freeze. After this optimisation it is totally smooth
even in debug mode.



Release Notes:

- Improved performance when searching in markdown preview
c7ad65e468Bennet Bo Fenner committed on 6/17/2026, 11:48:13 AM· committed by GitHubparent906b7e6
4 files changedLine totals unavailable