Skip to content

feat: column auto-fit (double-click divider + context menu)#511

Merged
datlechin merged 3 commits intomainfrom
feat/column-auto-fit
Mar 30, 2026
Merged

feat: column auto-fit (double-click divider + context menu)#511
datlechin merged 3 commits intomainfrom
feat/column-auto-fit

Conversation

@datlechin
Copy link
Copy Markdown
Collaborator

Summary

Add native macOS column auto-fit functionality to DataGridView, matching Finder/Numbers behavior.

Features

  • Double-click column divider → auto-fit that column to content (sizeToFitWidthOfColumn: delegate)
  • Right-click header → "Size to Fit" → auto-fit the clicked column
  • Right-click header → "Size All Columns to Fit" → auto-fit every column

Implementation

  • New calculateFitToContentWidth() in DataGridCellFactory — no max-width (800px) or max-chars (50) caps, unlike the initial-load calculation
  • All three features reuse the same uncapped width calculation
  • Works in both table data tab and SQL query results tab (shared DataGridView)
  • Column widths persist after auto-fit via existing ColumnLayoutStorage

Test plan

  • Double-click a column divider in header → column resizes to fit content
  • Right-click column header → "Size to Fit" → column resizes
  • Right-click column header → "Size All Columns to Fit" → all columns resize
  • Verify no max-width cap — wide content columns expand fully
  • Verify works in table tab (browsing data)
  • Verify works in query results tab (after running SQL)
  • Verify resized widths persist when switching tabs

- Implement tableView(_:sizeToFitWidthOfColumn:) delegate for native
  double-click-on-column-divider auto-fit (matches Finder/Numbers)
- Add "Size to Fit" to column header right-click menu
- Add "Size All Columns to Fit" to column header right-click menu
- All three reuse existing calculateOptimalColumnWidth() logic
- Works in both table data tab and SQL query results tab
@datlechin datlechin merged commit 7952527 into main Mar 30, 2026
2 checks passed
@datlechin datlechin deleted the feat/column-auto-fit branch March 30, 2026 08:41
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