Skip to content

Commit ef58902

Browse files
committed
fix: correct Shift+Click multi-column sort direction cycling
1 parent 3c5e278 commit ef58902

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

TablePro/Views/Results/DataGridCoordinator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ final class TableViewCoordinator: NSObject, NSTableViewDelegate, NSTableViewData
3232
var onHideColumn: ((String) -> Void)?
3333
var onMoveRow: ((Int, Int) -> Void)?
3434
var onNavigateFK: ((String, ForeignKeyInfo) -> Void)?
35+
var sortState = SortState()
3536
var getVisualState: ((Int) -> RowVisualState)?
3637
var dropdownColumns: Set<Int>?
3738
var typePickerColumns: Set<Int>?

TablePro/Views/Results/DataGridView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ struct DataGridView: NSViewRepresentable {
179179

180180
scrollView.documentView = tableView
181181
context.coordinator.tableView = tableView
182+
context.coordinator.sortState = sortState
182183
context.coordinator.onMoveRow = onMoveRow
183184
context.coordinator.rebuildColumnMetadataCache()
184185
if let connectionId {
@@ -232,6 +233,7 @@ struct DataGridView: NSViewRepresentable {
232233
)
233234
if currentIdentity == coordinator.lastIdentity {
234235
// Only refresh closure callbacks — they capture new state on each body eval
236+
coordinator.sortState = sortState
235237
coordinator.onCellEdit = onCellEdit
236238
coordinator.onSort = onSort
237239
coordinator.onAddRow = onAddRow
@@ -302,6 +304,7 @@ struct DataGridView: NSViewRepresentable {
302304
coordinator.onRefresh = onRefresh
303305
coordinator.onCellEdit = onCellEdit
304306
coordinator.onDeleteRows = onDeleteRows
307+
coordinator.sortState = sortState
305308
coordinator.onSort = onSort
306309
coordinator.onAddRow = onAddRow
307310
coordinator.onUndoInsert = onUndoInsert

TablePro/Views/Results/Extensions/DataGridView+Sort.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ extension TableViewCoordinator {
2424
onSort?(columnIndex, sortDescriptor.ascending, isMultiSort)
2525
}
2626

27-
/// Handle Shift+Click on column header for multi-column sort.
28-
/// NSTableView swallows Shift+Click on headers (sortDescriptorsDidChange never fires),
29-
/// so the custom SortableTableHeaderView calls this directly.
27+
// NSTableView swallows Shift+Click on headers, so SortableTableHeaderView calls this directly.
28+
// Cycles: not sorted -> ascending -> descending -> remove
3029
func handleShiftClickSort(columnIndex: Int) {
3130
guard columnIndex >= 0 && columnIndex < rowProvider.columns.count else { return }
32-
onSort?(columnIndex, true, true)
31+
let ascending = !sortState.columns.contains(where: { $0.columnIndex == columnIndex })
32+
onSort?(columnIndex, ascending, true)
3333
}
3434

3535
// MARK: - Double-Click Column Divider Auto-Fit

0 commit comments

Comments
 (0)