Skip to content

agent: lay out markdown tables from measured columns - #962

Merged
AnthonyRonning merged 1 commit into
masterfrom
md-tables
Sep 17, 2026
Merged

AnthonyRonning merged 1 commit into
masterfrom
md-tables

Conversation

@AnthonyRonning

Copy link
Copy Markdown
Contributor

Summary

Markdown tables in the agent transcript were laid out from character-count weights (flex_basis(weight/total) with min_w(0)), so a short column such as # got a sliver of the row and wrapped 863 into 86 / 3. This replaces that with a table layout that behaves like a browser's table-layout: auto, plus a few things browsers do not do for us.

Layout (app/src/ui/markdown/table.rs, new)

  • Every column is measured once per document from the shaped text of its cells, using the live chat face from window.text_style(): the widest line any cell needs (max-content) and the widest run gpui's line wrapper cannot break (min-content, computed from glyph positions with the wrapper's own word rules).
  • Cells carry those numbers as flex basis, minimum width and a shrink factor, so each row resolves the same column widths without a grid. A deficit is shared in proportion to each column's slack, like the CSS table algorithm: a column of numbers stays on one line while a prose column absorbs the loss and wraps.
  • A column that wraps never goes narrower than a readable measure (12 em); below that the table scrolls sideways instead of showing a word per line.
  • The table hugs its content when there is room; when the floors do not fit it scrolls sideways under an overlay scrollbar (new horizontal variant of ui::scrollbar), with the vertical wheel still reaching the transcript.
  • Measurements are cached on the block (TableMetrics, keyed by face, size and weight), so render stays a handful of allocations; a 200 × 6 table measures in ~29 ms cold, small tables in well under a millisecond.

Parser (app/src/ui/markdown.rs)

  • <br> (any spelling) becomes a line break inside cells and paragraphs.
  • \| inside a code span in a table shows as |.
  • Every row holds exactly the header's column count (short streaming rows are padded, long rows trimmed).

Why not Zed's implementation: Zed renders tables as a Taffy grid (grid_cols_max_content) inside a flex wrapper. At the pinned gpui revision (and upstream main) the text element answers a min-content probe with its full unwrapped width, so a grid cannot express a real floor per column and narrow columns can still split words. The flex-per-row approach with our own measurement gives the browser semantics and stays on the pinned gpui.

Verification

  • nix develop -c just ci green locally (fmt, clippy for all feature sets, tests).
  • New tests: segment/break-rule units, column_widths units, parser tests (<br>, escaped pipes, row padding), and #[gpui::test] layout tests that render tables in a window and assert cell bounds (content-width columns, hugging, deficit absorption, readable floor, forced scrolling).
  • Visual checks with a temporary local preview hook (not committed): light and dark themes; System, Manrope 18, Georgia 16 and Geist 13 faces (no spurious wraps, so measurement matches shaping with kerning); 3-, 6-, 9-, 10-, 14- and 25-column tables; a paragraph column among short ones; header-only and empty cells; emoji and CJK; inline styles and a long URL; <br> addresses; a 40-char hash; quoted and list-nested tables; a 200-row table; sideways wheel scrolling of overflowing tables.

Table columns were flex bases from character counts with a zero floor,
so a short column like `#` got a sliver of the row and wrapped `863`
into two lines. Tables now lay out the way a browser's automatic table
layout does: each column is measured once per document from its cells'
shaped text (widest line, widest unbreakable run) with the live chat
face, and every row resolves the same widths from those numbers as flex
basis, floor and shrink factor. Short columns stay on one line, prose
columns absorb the deficit in proportion to their slack, the table hugs
its content, and when the floors do not fit it scrolls sideways under a
new horizontal overlay scrollbar. A wrapping column never goes narrower
than a readable measure (12 em).

The parser turns `<br>` into a line break, shows `\|` inside table code
spans as a pipe, and pads or trims every row to the header's column
count so streaming tables keep their shape.
@AnthonyRonning
AnthonyRonning merged commit 2caa393 into master Sep 17, 2026
22 checks passed
@AnthonyRonning
AnthonyRonning deleted the md-tables branch September 17, 2026 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant