Create and use an NSTableView extension method: indexesOfAvailableRowsPassingTest.
This commit is contained in:
parent
bf233da3f0
commit
0d4a58e2ab
|
@ -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() {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue