markdown: Fix alignment of images in table cells (#64914)
## Summary
Images in Markdown table cells don't follow the column's alignment. An
icon in a `:---` column renders centered, and an image-only cell sits at
the top of the row while the text cells next to it are vertically
centered. I hit this using small milestone icons next to labels in
review tables.
This looks like a regression of the behavior added in #53465 (vertically
center cell content, respect column alignment) and #56179 (apply
alignment to cell content). My read of the history is that it broke when
#56427 added `push_image_child` for Agent Panel images; I haven't
bisected it.
Table cells use a column flex container with `justify_center` for
vertical centering. `push_image_child` switches the current container to
a wrapping row with `items_start`, so inside a cell `justify_center`
ends up centering horizontally and the image gets pinned to the top.
`TableState` now tracks whether we're inside a cell, and when an image
is pushed there the row's justification follows the column alignment and
its content is vertically centered. Images outside tables keep the
existing layout.
Not addressed here: long text next to an image in the same cell can
still wrap below it, since images are flex items rather than inline.
That also affects paragraphs, so I'd rather handle it separately.
| Before (1.21.0) | After |
| --- | --- |
| <img alt="zed-table-images-before"
src="https://github.com/user-attachments/assets/d4eaa856-abae-4470-85f8-f5aa4815be8b"
/> | <img alt="zed-table-images-after"
src="https://github.com/user-attachments/assets/22bbfb99-c474-4ae7-9b63-c276d6d3375c"
/> |
## Testing
- Added a layout test for images in left, center and right columns in a
tall row. It fails without the fix (a left-aligned image rendered
centered and 2px from the top of an 88px row).
- Added a test that paragraph images keep top alignment, plus a unit
test for the new cell state. Added `debug_selector`s to the image
wrapper and table cells so the tests can measure them.
- Manually compared the same document in 1.21.0 and this branch on
macOS, in light and dark themes and a narrow pane. Also checked a tall
image beside text (the #53465 case), a linked image (still clickable),
several images in one cell, an image in a header, and an HTML table
(unchanged).
To try it, open a Markdown preview of:
```markdown
| Marker | Commitment | Details |
|:---:|:---|:---|
|  | Engage counsel | A longer description that wraps across several lines and makes this row taller than the label. |
| Commitment | Details |
|:---|:---|
|  Engage counsel | A longer description that wraps across several lines. |
```
with any small SVG as `milestone.svg`, and narrow the preview until the
details wrap.
## 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 images in Markdown table cells ignoring column alignment and
vertical centering.
5d80b4e784andrew committed on 9/30/2026, 5:24:40 AM· committed by GitHubparent414428c