Repository navigation
agent: lay out markdown tables from measured columns - #962
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Markdown tables in the agent transcript were laid out from character-count weights (
flex_basis(weight/total)withmin_w(0)), so a short column such as#got a sliver of the row and wrapped863into86/3. This replaces that with a table layout that behaves like a browser'stable-layout: auto, plus a few things browsers do not do for us.Layout (
app/src/ui/markdown/table.rs, new)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).ui::scrollbar), with the vertical wheel still reaching the transcript.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|.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 cigreen locally (fmt, clippy for all feature sets, tests).column_widthsunits, 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).<br>addresses; a 40-char hash; quoted and list-nested tables; a 200-row table; sideways wheel scrolling of overflowing tables.