From 2797c607c30369c87ecb7b2ff07d347229b19992 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 7 Feb 2018 21:46:54 -0800 Subject: [PATCH] Update row height in timeline when font setting changes. --- .../Timeline/TimelineViewController.swift | 45 +++++++++++++------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/Evergreen/MainWindow/Timeline/TimelineViewController.swift b/Evergreen/MainWindow/Timeline/TimelineViewController.swift index 2d5243c75..3df1c350a 100644 --- a/Evergreen/MainWindow/Timeline/TimelineViewController.swift +++ b/Evergreen/MainWindow/Timeline/TimelineViewController.swift @@ -36,7 +36,7 @@ class TimelineViewController: NSViewController, UndoableCommandRunner { didSet { if showFeedNames != oldValue { updateShowAvatars() - tableView.rowHeight = currentRowHeight + updateTableViewRowHeight() } } } @@ -416,6 +416,7 @@ class TimelineViewController: NSViewController, UndoableCommandRunner { rowHeightWithFeedName = calculateRowHeight(showingFeedNames: true) rowHeightWithoutFeedName = calculateRowHeight(showingFeedNames: false) + updateTableViewRowHeight() } } @@ -587,6 +588,11 @@ private extension TimelineViewController { } } + func updateTableViewRowHeight() { + + tableView.rowHeight = currentRowHeight + } + func updateShowAvatars() { if showFeedNames { @@ -617,17 +623,32 @@ private extension TimelineViewController { func sortDirectionDidChange() { - let selectedArticleIDs = selectedArticles.articleIDs() + performBlockAndRestoreSelection { + let unsortedArticles = Set(articles) + updateArticles(with: unsortedArticles) + } + } - let unsortedArticles = Set(articles) - updateArticles(with: unsortedArticles) + func selectedArticleIDs() -> [String] { - selectArticles(selectedArticleIDs) + return selectedArticles.articleIDs() + } + + func restoreSelection(_ articleIDs: [String]) { + + selectArticles(articleIDs) if tableView.selectedRow != -1 { tableView.scrollRowToVisible(tableView.selectedRow) } } + func performBlockAndRestoreSelection(_ block: (() -> Void)) { + + let savedSelection = selectedArticleIDs() + block() + restoreSelection(savedSelection) + } + // MARK: Fetching Articles func fetchArticles() { @@ -672,15 +693,13 @@ private extension TimelineViewController { return } - let selectedArticleIDs = selectedArticles.articleIDs() - - var unsortedArticles = fetchUnsortedArticles(for: representedObjects) - unsortedArticles.formUnion(Set(articles)) - updateArticles(with: unsortedArticles) - - selectArticles(selectedArticleIDs) + performBlockAndRestoreSelection { + var unsortedArticles = fetchUnsortedArticles(for: representedObjects) + unsortedArticles.formUnion(Set(articles)) + updateArticles(with: unsortedArticles) + } } - + func selectArticles(_ articleIDs: [String]) { let indexesToSelect = articles.indexesForArticleIDs(Set(articleIDs))