# markdown: Fix text selection position in centered/right-aligned markdown table cells \(\#57283\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/735980b158e447add9a87641828707fb15837c31)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 735980b158e447add9a87641828707fb15837c31

Requested commit: 735980b158e447add9a87641828707fb15837c31

Commit: 735980b158e447add9a87641828707fb15837c31

Tree: 56ed955f2a6ae0ed8de07329e0133b5df2ef8217

Author: Remco Smits

Committer: GitHub

## Message

```
markdown: Fix text selection position in centered/right-aligned markdown table cells (#57283)

Table header cells are always center-aligned. When selecting text in
them, the selection highlight was drawn at the left edge of the cell
instead of over the actual visible text. Clicking on a character also
mapped to the wrong source index.

The bug was that `bounds_for_source_range` and
`source_index_for_position` used raw layout x-coordinates (which start
at 0), without accounting for the horizontal offset GPUI applies when
rendering center- or right-aligned text.

The fix stores the `TextAlign` on each `RenderedLine` at flush time,
then uses it to compute an alignment offset per wrapped row segment.
That offset is:
- subtracted from the click position before resolving it to a source
index
- added to the x-coordinates when computing selection highlight bounds

**Before**:


https://github.com/user-attachments/assets/49fd7748-eb1b-4199-bc2f-23cddcb528c5

**After**:


https://github.com/user-attachments/assets/93657652-d548-4e5a-b011-be29bb0a3d9e


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 is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Markdown: Fixed text selection highlight appearing at the wrong
position when selecting text in markdown table headers.
```

## Parents

- [954ee58c15be92205cff66bc1dbed7aa497f294d](https://git.cafe/gitcafe/zed/commit/954ee58c15be92205cff66bc1dbed7aa497f294d?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/735980b158e447add9a87641828707fb15837c31?format=markdown)
