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 {
return
}
let savedSelection = selectedNodes
rebuildTreeAndReloadDataIfNeeded()
configureCellsForRepresentedObject(object as AnyObject)
restoreSelection(to: savedSelection, sendNotificationIfChanged: true)
}
@objc func userDidRequestSidebarSelection(_ note: Notification) {
@ -343,6 +345,26 @@ private extension SidebarViewController {
}
}
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]?) {
var userInfo = UserInfoDictionary()