Create and use an NSTableView extension method: indexesOfAvailableRowsPassingTest.

This commit is contained in:
Brent Simmons 2018-01-06 12:12:31 -08:00
parent bf233da3f0
commit 0d4a58e2ab
2 changed files with 21 additions and 6 deletions

View File

@ -331,19 +331,20 @@ class TimelineViewController: NSViewController, UndoableCommandRunner {
return
}
var indexes = IndexSet()
tableView.enumerateAvailableRowViews { (rowView, row) in
let indexesToReload = tableView.indexesOfAvailableRowsPassingTest { (row) -> Bool in
guard let article = articles.articleAtRow(row), let authors = article.authors, !authors.isEmpty else {
return
return false
}
for author in authors {
if author.avatarURL == avatarURL {
indexes.insert(row)
return
return true
}
}
return false
}
if let indexesToReload = indexesToReload {
reloadCells(for: indexesToReload)
}
reloadCells(for: indexes)
}
func fontSizeInDefaultsDidChange() {

View File

@ -16,6 +16,20 @@ public extension NSTableView {
}
}
func indexesOfAvailableRowsPassingTest(_ test: (Int) -> Bool) -> IndexSet? {
// Checks visible and in-flight rows.
var indexes = IndexSet()
enumerateAvailableRowViews { (_, row) in
if test(row) {
indexes.insert(row)
}
}
return indexes.isEmpty ? nil : indexes
}
func scrollTo(row: Int) {
guard let scrollView = self.enclosingScrollView else {