diff --git a/NetNewsWire/MainWindow/Timeline/ArticleArray.swift b/NetNewsWire/MainWindow/Timeline/ArticleArray.swift index 575e70d0b..d8878eaa7 100644 --- a/NetNewsWire/MainWindow/Timeline/ArticleArray.swift +++ b/NetNewsWire/MainWindow/Timeline/ArticleArray.swift @@ -102,5 +102,20 @@ extension Array where Element == Article { let articles = self.filter{ !$0.status.read } return articles.isEmpty ? nil : articles } + + func representSameArticlesInSameOrder(as otherArticles: [Article]) -> Bool { + if self.count != otherArticles.count { + return false + } + var i = 0 + for article in self { + let otherArticle = otherArticles[i] + if article.account != otherArticle.account || article.articleID != otherArticle.articleID { + return false + } + i += 1 + } + return true + } } diff --git a/NetNewsWire/MainWindow/Timeline/TimelineViewController.swift b/NetNewsWire/MainWindow/Timeline/TimelineViewController.swift index 2da1b9735..0b1ddcbfa 100644 --- a/NetNewsWire/MainWindow/Timeline/TimelineViewController.swift +++ b/NetNewsWire/MainWindow/Timeline/TimelineViewController.swift @@ -28,11 +28,20 @@ class TimelineViewController: NSViewController, UndoableCommandRunner { var articles = ArticleArray() { didSet { - if articles != oldValue { - updateShowAvatars() - articleRowMap = [String: Int]() - tableView.reloadData() + if articles == oldValue { + return } + if articles.representSameArticlesInSameOrder(as: oldValue) { + // When the array is the same — same articles, same order — + // but some data in some of the articles may have changed. + // Just reload visible cells in this case: don’t call reloadData. + articleRowMap = [String: Int]() + reloadVisibleCells() + return + } + updateShowAvatars() + articleRowMap = [String: Int]() + tableView.reloadData() } } @@ -440,6 +449,13 @@ class TimelineViewController: NSViewController, UndoableCommandRunner { } return nil } + + private func reloadVisibleCells() { + guard let indexes = tableView.indexesOfAvailableRows() else { + return + } + reloadVisibleCells(for: indexes) + } private func reloadVisibleCells(for articles: [Article]) { reloadVisibleCells(for: Set(articles.articleIDs()))