fix: auto-width columns shrink when widest row is removed#6590
Closed
xbrxr03 wants to merge 1 commit into
Closed
Conversation
When remove_row() is called on a DataTable with auto-width columns, the column widths were never recalculated. This meant that removing the row containing the widest cell in a column left the column stuck at its old width, even though the remaining rows were narrower. The fix adds _recalculate_auto_width_columns() which recomputes content_width for each auto-width column by measuring all remaining cells after row removal. This is called from remove_row() after deleting the row data but before refreshing the layout. Fixes Textualize#3449
Member
|
Your PR has been closed due to a AI policy violation. Please read the following before submitting further PRs. https://github.com/Textualize/textual/blob/main/AI_POLICY.md |
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
Fixes #3449 — DataTable auto-width columns do not shrink back down when the row containing the widest cell is removed.
The Bug
When
remove_row()is called on a DataTable with auto-width columns, the column widths are never recalculated. This means removing the row that contained the widest cell in a column leaves the column stuck at its old width, even though all remaining rows are narrower.This is because
remove_row()deletes the row data and updates row locations, but never triggers a column width recalculation. The existing_update_column_widths()method only handles cells that were explicitly updated (via theupdated_cellsset), so it cannot detect when a removed row was the one setting the maximum width.The Fix
Added
_recalculate_auto_width_columns()which recomputescontent_widthfor each auto-width column by measuring all remaining cells after row removal. Called fromremove_row()after deleting the row data but before refreshing the layout.Key behaviors:
max(widest remaining cell, label width)Testing
test_remove_row_auto_width_columns_shrink— verifies that removing the widest row shrinks the column widthReproduction
The original issue includes a complete reproduction app. With this fix:
"Aleksandr Sadovnikov ============="(the widest cell)