From 3ab1412dc679b43e0b612485286e80408b15166b Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 30 Aug 2019 02:39:54 -0500 Subject: [PATCH] Preserve article selection when articles are downloaded (for iPad only) --- iOS/AppCoordinator.swift | 4 ++++ .../MasterTimelineViewController.swift | 14 ++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/iOS/AppCoordinator.swift b/iOS/AppCoordinator.swift index cbc36870d..d9dddaa00 100644 --- a/iOS/AppCoordinator.swift +++ b/iOS/AppCoordinator.swift @@ -883,7 +883,11 @@ private extension AppCoordinator { func replaceArticles(with unsortedArticles: Set
) { let sortedArticles = Array(unsortedArticles).sortedByDate(sortDirection) if articles != sortedArticles { + let article = currentArticle articles = sortedArticles + if let articleID = article?.articleID, let index = row(for: articleID) { + currentArticleIndexPath = IndexPath(row: index, section: 0) + } } } diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index b1df0488c..a665ba69e 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -475,15 +475,13 @@ private extension MasterTimelineViewController { } func performBlockAndRestoreSelection(_ block: (() -> Void)) { - let articleID: String? = { - if let indexPath = tableView.indexPathForSelectedRow, indexPath.row < coordinator.articles.count { - return coordinator.articles[indexPath.row].articleID - } - return nil - }() - + guard traitCollection.userInterfaceIdiom == .pad else { + block() + return + } + + let articleID = coordinator.currentArticle?.articleID block() - if let articleID = articleID, let index = coordinator.indexesForArticleIDs(Set([articleID])).first { let indexPath = IndexPath(row: index, section: 0) tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)