diff --git a/Mac/MainWindow/Sidebar/SidebarViewController.swift b/Mac/MainWindow/Sidebar/SidebarViewController.swift index 559a9da11..8e2be6b86 100644 --- a/Mac/MainWindow/Sidebar/SidebarViewController.swift +++ b/Mac/MainWindow/Sidebar/SidebarViewController.swift @@ -345,9 +345,21 @@ protocol SidebarDelegate: class { // MARK: - API func rebuildTreeAndRestoreSelection() { + + let savedAccounts = treeController.rootNode.childNodes.compactMap { $0.representedObject as? Account } + let savedSelection = selectedNodes rebuildTreeAndReloadDataIfNeeded() restoreSelection(to: savedSelection, sendNotificationIfChanged: true) + + // Automatically expand any new or newly active accounts + AccountManager.shared.activeAccounts.forEach { account in + if !savedAccounts.contains(account) { + let accountNode = treeController.nodeInTreeRepresentingObject(account) + outlineView.expandItem(accountNode) + } + } + } }