gpui: Fix panic when hit testing past a wrapped line's width (#64672)
# Objective
Fixes ZED-BW8 (``called `Option::unwrap()` on a `None` value`` in
`WrappedLineLayout::_index_for_position`). ZED-75K and ZED-81Z are the
same panic from older releases, and they almost always happen on Linux
when hovering markdown.
Hit testing a wrapped row assumes the next wrap boundary glyph never
sits past the line's width. cosmic-text breaks that assumption. It
computes the width by summing word widths but positions glyphs by
accumulating advances, so a trailing zero-width glyph (zero-width space,
ZWJ, emoji variation selector, combining accent) can land a few ulps
past the width. When that glyph is also a wrap boundary, the row before
it extends slightly past the width. A hit in that sliver made
`index_for_x` return `None`, and we unwrapped it.
## Solution
We now treat `None` from `index_for_x` as past the end of the row and
return `Err` with the row's end index, the same as positions beyond the
row's right edge. `index_for_x` itself is unchanged, so editor click
placement isn't affected.
## Testing
- `index_for_position_past_line_width` shapes `"Warning: this will
delete files\u{200b}"` with the bundled IBM Plex Sans at a 4px wrap
width, then hit tests exactly in the sliver past the width. It panics
without the fix.
- This isn't practical to reproduce by hand, since the sliver is about
1e-5px wide. macOS uses CoreText, which I don't think produces the
overshoot; the web build shares cosmic-text with Linux.
## Self-Review Checklist:
- [x] I've reviewed my own diff for quality, security, and reliability
- [x] 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
Release Notes:
- Fixed a rare crash when hovering wrapped markdown text on Linux.
- [GPUI] Fixed a panic in `WrappedLineLayout::index_for_position` when
hit testing past a wrapped line's width.
e71963a599Agus Zubiaga committed on 9/23/2026, 5:59:33 PM· committed by GitHubparentbd692a8