From 61ef71037509ca49188ea458fbad1b99e7534ffd Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 19 Sep 2026 11:41:48 -0700 Subject: [PATCH] Stop autosaved column sort descriptors from overriding the window's sort. --- .../Timeline/TimelineViewController+ColumnLayout.swift | 9 ++++++++- Mac/MainWindow/Timeline/TimelineViewController.swift | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Mac/MainWindow/Timeline/TimelineViewController+ColumnLayout.swift b/Mac/MainWindow/Timeline/TimelineViewController+ColumnLayout.swift index 788106660..8c5546109 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController+ColumnLayout.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController+ColumnLayout.swift @@ -98,7 +98,9 @@ extension TimelineViewController { func tableView(_ tableView: NSTableView, sortDescriptorsDidChange oldDescriptors: [NSSortDescriptor]) { // A header click. Don’t sort here — ask the container, which owns the window’s sort. // Setting sortDescriptors programmatically lands here too, and the equality check ends that loop. - guard let descriptor = tableView.sortDescriptors.first, let rawKey = descriptor.key, let key = ArticleSortKey(rawValue: rawKey) else { + // The table also autosaves sort descriptors under its autosaveName and restores them when it’s configured. + // Those belong to whatever window last saved, so they’re ignored — the window’s own sort is applied right after. + guard !isConfiguringTableColumns, let descriptor = tableView.sortDescriptors.first, let rawKey = descriptor.key, let key = ArticleSortKey(rawValue: rawKey) else { return } let direction: ComparisonResult = descriptor.ascending ? .orderedAscending : .orderedDescending @@ -131,6 +133,10 @@ private extension TimelineViewController { } func configureTableViewForColumnLayout() { + isConfiguringTableColumns = true + defer { + isConfiguringTableColumns = false + } removeAllTableColumns() for column in TimelineColumn.allCases { tableView.addTableColumn(column.makeTableColumn()) @@ -144,6 +150,7 @@ private extension TimelineViewController { // Set the name before turning autosave on so saved widths and order are read back. tableView.autosaveName = columnAutosaveName tableView.autosaveTableColumns = true + isConfiguringTableColumns = false applySortDescriptorsToTableView() } diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index 5097da133..2af285c0f 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -204,6 +204,8 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr } // The nib’s single column, kept so standard layout can put it back. var standardColumn: NSTableColumn? + // Set while columns are added and autosaved state is restored, which fires sortDescriptorsDidChange. + var isConfiguringTableColumns = false var standardRowHeight: CGFloat { currentRowHeight }