Restore the selection after rebuilding the sidebar after a name change.

This commit is contained in:
Brent Simmons 2019-02-02 17:01:40 -08:00
parent 25b6027745
commit 3f57cdf4f7
1 changed files with 23 additions and 1 deletions

View File

@ -118,8 +118,10 @@ import RSCore
guard let object = note.object else { guard let object = note.object else {
return return
} }
let savedSelection = selectedNodes
rebuildTreeAndReloadDataIfNeeded() rebuildTreeAndReloadDataIfNeeded()
configureCellsForRepresentedObject(object as AnyObject) configureCellsForRepresentedObject(object as AnyObject)
restoreSelection(to: savedSelection, sendNotificationIfChanged: true)
} }
@objc func userDidRequestSidebarSelection(_ note: Notification) { @objc func userDidRequestSidebarSelection(_ note: Notification) {
@ -342,7 +344,27 @@ private extension SidebarViewController {
outlineView.reloadData() outlineView.reloadData()
} }
} }
func restoreSelection(to nodes: [Node], sendNotificationIfChanged: Bool) {
if selectedNodes == nodes { // Nothing to do?
return
}
var indexes = IndexSet()
for node in nodes {
let row = outlineView.row(forItem: node as Any)
if row > -1 {
indexes.insert(row)
}
}
outlineView.selectRowIndexes(indexes, byExtendingSelection: false)
if selectedNodes != nodes && sendNotificationIfChanged {
postSidebarSelectionDidChangeNotification(selectedObjects)
}
}
func postSidebarSelectionDidChangeNotification(_ selectedObjects: [AnyObject]?) { func postSidebarSelectionDidChangeNotification(_ selectedObjects: [AnyObject]?) {
var userInfo = UserInfoDictionary() var userInfo = UserInfoDictionary()