Skip to content

[codex] Fix markdown table column layout#2202

Open
suxiaoshao wants to merge 1 commit intolongbridge:mainfrom
suxiaoshao:issue-2197-markdown-table-wrap
Open

[codex] Fix markdown table column layout#2202
suxiaoshao wants to merge 1 commit intolongbridge:mainfrom
suxiaoshao:issue-2197-markdown-table-wrap

Conversation

@suxiaoshao
Copy link
Copy Markdown
Contributor

@suxiaoshao suxiaoshao commented Mar 30, 2026

Closes #2197

Description

This PR fixes markdown table cells overflowing or wrapping incorrectly in TextView::markdown(...).

The previous table renderer approximated column widths with content length and then relied on flex layout. That diverged from browser table layout behavior in two important ways:

  1. text length is not a reliable proxy for rendered width, especially for mixed CJK / ASCII / emoji content
  2. letting flex shrink columns independently does not match browser-style table column allocation, so short columns could wrap unexpectedly while long columns failed to absorb the available width correctly

The fix follows the browser table-layout: auto model more closely:

  • measure each column's rendered preferred width from actual shaped text
  • measure each column's min-content width from the longest unbreakable segment in its cells
  • allocate final column widths against the table's actual available width
  • when space is limited, shrink only the columns that can shrink, down to their measured minimum width
  • when extra space is available, distribute it across columns proportionally from their preferred widths
  • render cells with explicit final widths so the text layout receives stable width constraints

This keeps short columns stable, allows long columns to wrap first, and matches browser table behavior much more closely for both two-column and multi-column markdown tables.

This work was investigated and implemented with assistance from Codex GPT-5.4.

Screenshot

Before After
Image image

How to Test

  1. Render markdown with a table that has a short first column and a long second column in a constrained-width container.
  2. Confirm that the short header or short body cells do not wrap prematurely.
  3. Confirm that the long column wraps within the table width instead of overflowing horizontally.
  4. Render a three-column table where the middle column is long and the last column is short.
  5. Confirm that the middle column shrinks and wraps before the short last column is compressed.

Validated locally with:

  • cargo test -p gpui-component table_cell_segments --lib
  • cargo test -p gpui-component allocate_widths --lib

Checklist

  • I have read the CONTRIBUTING document and followed the guidelines.
  • Reviewed the changes in this PR and confirmed AI generated code (If any) is accurate.
  • Passed cargo run for story tests related to the changes.
  • Tested macOS, Windows and Linux platforms performance (if the change is platform-specific)

@suxiaoshao suxiaoshao marked this pull request as ready for review March 30, 2026 19:34
@huacnlee
Copy link
Copy Markdown
Member

It seems the implementation direction might be wrong, as it uses a lot of GPUI basic layout text APIs, which shouldn't be so complicated.

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.

markdown table cells do not wrap and can overflow horizontally

2 participants