Skip to content

text_view: Keep narrow table columns on one line - #3399

Merged
madcodelife merged 2 commits into
mainfrom
text-view-table-column-fit
Oct 8, 2026
Merged

madcodelife merged 2 commits into
mainfrom
text-view-table-column-fit

Conversation

@madcodelife

@madcodelife madcodelife commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Description

Short table columns in TextView often wrap a single trailing character onto its own line (冷启动(毫秒 + ), Memo + ry). The wrap layout sized columns by UTF-8 byte length, and the scroll layout shrank every column by the same ratio, so a column that nearly fit lost its last character.

Both layouts now size columns from measured text width. When the table is wider than its frame, narrow columns keep their full width and only the widest ones shrink and wrap. Widths are also rounded up to the device pixel, and headers are measured with the table_head / table_cell styles they render with.

Behavior change: column widths in the default wrap layout change for most tables.

Not in this PR: breaks before full-width closing punctuation ()) and after opening punctuation (() come from GPUI's line wrapper and need a GPUI change.

The markdown_table example gets a "Column fitting" section with the same table in Chinese and English.

Screenshot

cargo run -p markdown_table at 640px wide.

Table Before After
English, wrap table-en-before-wrap table-en-after-wrap
English, scroll table-en-before-adaptive table-en-after-adaptive
Chinese, wrap table-zh-before-wrap table-zh-after-wrap
Chinese, scroll table-zh-before-adaptive table-zh-after-adaptive

How to Test

  • cargo test -p gpui-base --lib: passed. The new table_keeps_narrow_columns_on_one_line_while_wide_ones_wrap fails on the parent commit.
  • cargo run -p markdown_table, scroll to "6. Column fitting", switch layouts and narrow the window.

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)

madcodelife and others added 2 commits October 7, 2026 22:01
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…finements

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@madcodelife
madcodelife merged commit 3cc2d0d into main Oct 8, 2026
16 checks passed
@madcodelife
madcodelife deleted the text-view-table-column-fit branch October 8, 2026 01:51
linruohan pushed a commit to linruohan/gpui-component that referenced this pull request Oct 9, 2026
## Description

Short table columns in `TextView` often wrap a single trailing character
onto its own line (`冷启动(毫秒` + `)`, `Memo` + `ry`). The wrap layout sized
columns by UTF-8 byte length, and the scroll layout shrank every column
by the same ratio, so a column that nearly fit lost its last character.

Both layouts now size columns from measured text width. When the table
is wider than its frame, narrow columns keep their full width and only
the widest ones shrink and wrap. Widths are also rounded up to the
device pixel, and headers are measured with the `table_head` /
`table_cell` styles they render with.

**Behavior change:** column widths in the default wrap layout change for
most tables.

Not in this PR: breaks before full-width closing punctuation (`)`) and
after opening punctuation (`(`) come from GPUI's line wrapper and need a
GPUI change.

The `markdown_table` example gets a "Column fitting" section with the
same table in Chinese and English.

## Screenshot

`cargo run -p markdown_table` at 640px wide.

| Table | Before | After |
| --- | --- | --- |
| English, wrap | <img width="640" height="440"
alt="table-en-before-wrap"
src="https://github.com/user-attachments/assets/f842cb34-65ee-4190-aa49-b1b2d8c93c36"
/> | <img width="640" height="440" alt="table-en-after-wrap"
src="https://github.com/user-attachments/assets/ddf5ac5c-1373-4b76-a9db-61c1108ecfcb"
/> |
| English, scroll | <img width="640" height="440"
alt="table-en-before-adaptive"
src="https://github.com/user-attachments/assets/e0369e63-7af5-46e7-9d50-8341d0b7f3d9"
/> | <img width="640" height="440" alt="table-en-after-adaptive"
src="https://github.com/user-attachments/assets/6ea609ca-992f-4be7-aa2d-45da8ed64be6"
/> |
| Chinese, wrap | <img width="640" height="440"
alt="table-zh-before-wrap"
src="https://github.com/user-attachments/assets/316ec94e-59c5-469f-be10-d296e5ad6c0e"
/> | <img width="640" height="440" alt="table-zh-after-wrap"
src="https://github.com/user-attachments/assets/663589de-c591-4871-911f-91a8558b3d3a"
/> |
| Chinese, scroll | <img width="640" height="440"
alt="table-zh-before-adaptive"
src="https://github.com/user-attachments/assets/ac55f40e-09a3-476f-ac00-65d8f816a73b"
/> | <img width="640" height="440" alt="table-zh-after-adaptive"
src="https://github.com/user-attachments/assets/d0d6ab7a-72b4-4813-aecc-6d4700aa7c71"
/> |

## How to Test

- `cargo test -p gpui-base --lib`: passed. The new
`table_keeps_narrow_columns_on_one_line_while_wide_ones_wrap` fails on
the parent commit.
- `cargo run -p markdown_table`, scroll to "6. Column fitting", switch
layouts and narrow the window.

## Checklist

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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