Keep the current article in the timeline, and keep it selected, when the timeline updates and the sidebar selection hasn't changed. Fixes #5140. Fixes #5340.

This commit is contained in:
Brent Simmons committed 2026-07-26 11:38:54 -07:00
1 parent e99f23d07e
commit fda761b206
1 file changed
+19 -5
@@ -722,26 +722,26 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
@objc func accountStateDidChange(_ note: Notification) {
if representedObjectsContainsAnyPseudoFeed() {
fetchAndReplaceArticlesAsync()
fetchAndReplacePreservingSelectionAsync()
}
}
@objc func accountsDidChange(_ note: Notification) {
if representedObjectsContainsAnyPseudoFeed() {
fetchAndReplaceArticlesAsync()
fetchAndReplacePreservingSelectionAsync()
}
}
@objc func userDidDeleteAccount(_ note: Notification) {
undoManager?.removeAllActions() // Undo stack may contain actions for the deleted account.
if representedObjectsContainsAnyPseudoFeed() {
fetchAndReplaceArticlesAsync()
fetchAndReplacePreservingSelectionAsync()
}
}
@objc func containerChildrenDidChange(_ note: Notification) {
if representedObjectsContainsAnyPseudoFeed() || representedObjectsContainAnyFolder() {
fetchAndReplaceArticlesAsync()
fetchAndReplacePreservingSelectionAsync()
}
}
@@ -1043,6 +1043,19 @@ private extension TimelineViewController {
}
}
// The current article should stay in the timeline, and stay selected,
// when the timeline updates and the sidebar selection hasn't changed —
// even if the new fetch wouldn't otherwise include it.
func fetchAndReplacePreservingSelectionAsync() {
if let article = oneSelectedArticle, let account = article.account {
exceptionArticleFetcher = SingleArticleFetcher(account: account, articleID: article.articleID)
}
let savedSelection = selectedArticleIDs()
fetchAndReplaceArticlesAsync { [weak self] in
self?.restoreSelection(savedSelection)
}
}
func updateUnreadCount() {
var count = 0
for article in articles {
@@ -1190,7 +1203,7 @@ private extension TimelineViewController {
replaceArticles(with: fetchedArticles)
}
func fetchAndReplaceArticlesAsync() {
func fetchAndReplaceArticlesAsync(completion: (() -> Void)? = nil) {
// To be called when we need to do an entire fetch, but an async delay is okay.
// Example: we have the Today feed selected, and the calendar day just changed.
cancelPendingAsyncFetches()
@@ -1206,6 +1219,7 @@ private extension TimelineViewController {
fetchUnsortedArticlesAsync(for: representedObjects) { [weak self] (articles) in
self?.replaceArticles(with: articles)
completion?()
}
}