Skip to content

data_table: Rework column/table width API#51060

Merged
Anthony-Eid merged 14 commits intozed-industries:mainfrom
HalavicH:feat/data-table/rework-width-api
Apr 1, 2026
Merged

data_table: Rework column/table width API#51060
Anthony-Eid merged 14 commits intozed-industries:mainfrom
HalavicH:feat/data-table/rework-width-api

Conversation

@HalavicH
Copy link
Copy Markdown
Contributor

@HalavicH HalavicH commented Mar 8, 2026

data_table: Replace column width builder API with ColumnWidthConfig enum

This PR consolidates the data table width configuration API from three separate builder methods (.column_widths(), .resizable_columns(), .width()) into a single .width_config(ColumnWidthConfig) call. This makes invalid state combinations unrepresentable and clarifies the two distinct width management modes.

What changed:

  • Introduces ColumnWidthConfig enum with two variants:
    • Static: Fixed column widths, no resize handles
    • Redistributable: Drag-to-resize columns that redistribute space within a fixed table width
  • Introduces TableResizeBehavior enum (None, Resizable, MinSize(f32)) for per-column resize policy
  • Renames TableColumnWidthsRedistributableColumnsState to better reflect its purpose
  • Extracts all width management logic into a new width_management.rs module
  • Updates all callers: csv_preview, git_graph, keymap_editor, edit_prediction_context_view
pub enum ColumnWidthConfig {
    /// Static column widths (no resize handles).
    Static {
        widths: StaticColumnWidths,
        /// Controls widths of the whole table.
        table_width: Option<DefiniteLength>,
    },
    /// Redistributable columns — dragging redistributes the fixed available space
    /// among columns without changing the overall table width.
    Redistributable {
        entity: Entity<RedistributableColumnsState>,
        table_width: Option<DefiniteLength>,
    },
}

Why:

The old API allowed callers to combine methods incorrectly. The new enum-based design enforces correct usage at compile time and provides a clearer path for adding independently resizable columns in PR #3.

Context:

This is part 2 of a 3-PR series improving data table column width handling:

  1. #51059 - Extract modules into separate files (mechanical change)
  2. This PR: Introduce width config enum for redistributable column widths (API rework)
  3. Implement independently resizable column widths (new feature)

The series builds on previously merged infrastructure:

  • #46341 - Data table dynamic column support
  • #46190 - Variable row height mode for data tables

Primary beneficiary: CSV preview feature (#48207)

Anthony's note

This PR also fixes the table dividers being a couple pixels off, and the csv preview from having double line rendering for a single column in some cases.

Before you mark this PR as ready for review, make sure that you have:

  • Added a solid test coverage and/or screenshots from doing manual testing
  • Done a self-review taking into account security and performance aspects
  • Aligned any UI changes with the UI checklist

Release Notes:

  • N/A

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 8, 2026
@HalavicH HalavicH changed the title (stacked on top of #51059) Rework column/table width API in data table (stacked on top of #51059. Don't review) Rework column/table width API in data table Mar 8, 2026
Anthony-Eid pushed a commit that referenced this pull request Mar 9, 2026
Extract data table modules into separate files

This PR extracts the `tests` and `table_row` modules from
`data_table.rs` into separate files to improve code organization. This
is preparatory work for the upcoming column width API rework (#2 in the
series), where separating mechanical changes from logical changes will
make the review easier.

The extraction was performed using rust-analyzer's "Extract module to
file" command.

**Context:**

This is part 1 of a 3-PR series improving data table column width
handling:
1. **This PR**: Extract modules into separate files (mechanical change)
2. [#51060](#51060) -
Introduce width config enum for redistributable column widths (API
rework)
3. Implement independently resizable column widths (new feature)

The series builds on previously merged infrastructure:
- [#46341](#46341) - Data
table dynamic column support
- [#46190](#46190) - Variable
row height mode for data tables

Primary beneficiary: CSV preview feature
([#48207](#48207))

Release Notes:

- N/A
@HalavicH HalavicH changed the title (stacked on top of #51059. Don't review) Rework column/table width API in data table Rework column/table width API in data table Mar 9, 2026
@HalavicH HalavicH marked this pull request as ready for review March 9, 2026 20:06
Copy link
Copy Markdown
Contributor

@Anthony-Eid Anthony-Eid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we end up splitting up some of data_table.rs into width_managements.rs that should be it's own PR, just to make this one as easy to review as possible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather prevent separating data_table.rs into two files, it's inconsistent with the rest of the Zed codebase for the most part, and it would make finding the resizable columns stuff harder for devs that are used to our current organization patterns

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay i'll merge it back in

Comment on lines 857 to 861
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the motivation behind this change? Cargo.toml changes like this should be in their own PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems i accidentally commited redundant commit

Combine column widths, resize behavior, and table width into a single
ColumnWidthConfig enum that makes invalid states unrepresentable.

This replaces the old `.column_widths()` + `.resizable_columns()` +
`.width()` builder pattern with `.width_config(config)`.
@HalavicH HalavicH force-pushed the feat/data-table/rework-width-api branch from 07ffa1f to a461da9 Compare March 10, 2026 16:41
@HalavicH
Copy link
Copy Markdown
Contributor Author

Does anything besides conflicts prevent this pr from being merged?

@Anthony-Eid
Copy link
Copy Markdown
Contributor

Does anything besides conflicts prevent this pr from being merged?

There were some bugs with this PR that I just fixed. The resize behavior didn't work and all tables became resizable instead of being explicitly marked with the intractable function like it was before.

I also fixed the pixel mis alignment issues with the dividers for columns.

@Anthony-Eid Anthony-Eid enabled auto-merge (squash) April 1, 2026 04:43
@Anthony-Eid Anthony-Eid changed the title Rework column/table width API in data table data_table: Rework column/table width API Apr 1, 2026
@Anthony-Eid Anthony-Eid merged commit a3964a5 into zed-industries:main Apr 1, 2026
49 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants