@@ -93,14 +93,13 @@ struct ProjectNavigatorOutlineView: NSViewControllerRepresentable {
9393 if outlineView. window? . firstResponder !== outlineView
9494 && outlineView. window? . firstResponder is NSTextView
9595 && ( outlineView. window? . firstResponder as? NSView ) ? . isDescendant ( of: outlineView) == true {
96- // Find the cell being edited by traversing up from the text view
97- var currentView = outlineView. window? . firstResponder as? NSView
9896 capturedSelectionRange = ( outlineView. window? . firstResponder as? NSTextView ) ? . selectedRange
9997
98+ // Find the cell being edited by traversing up from the text view
99+ var currentView = outlineView. window? . firstResponder as? NSView
100100 while let view = currentView {
101101 if let cell = view as? ProjectNavigatorTableViewCell ,
102- let fileItem = cell. fileItem,
103- fileItem. phantomFile != nil {
102+ let fileItem = cell. fileItem, fileItem. phantomFile != nil {
104103 editingPhantomFile = fileItem
105104 capturedText = cell. textField? . stringValue
106105 break
@@ -114,33 +113,32 @@ struct ProjectNavigatorOutlineView: NSViewControllerRepresentable {
114113 outlineView. reloadItem ( item, reloadChildren: true )
115114 }
116115
116+ // Restore selected items where the files still exist.
117+ let selectedIndexes = selectedRows. compactMap ( { outlineView. row ( forItem: $0) } ) . filter ( { $0 >= 0 } )
118+ controller? . shouldSendSelectionUpdate = false
119+ outlineView. selectRowIndexes ( IndexSet ( selectedIndexes) , byExtendingSelection: false )
120+ controller? . shouldSendSelectionUpdate = true
121+
117122 // If we were editing a phantom file, restore the text field and focus
118123 if let phantomFile = editingPhantomFile, let text = capturedText {
119124 let row = outlineView. row ( forItem: phantomFile)
120- if row >= 0 ,
121- let cell = outlineView. view (
125+ if row >= 0 , let cell = outlineView. view (
122126 atColumn: 0 ,
123127 row: row,
124128 makeIfNecessary: false
125- ) as? ProjectNavigatorTableViewCell {
129+ ) as? ProjectNavigatorTableViewCell {
126130 cell. textField? . stringValue = text
127131 outlineView. window? . makeFirstResponder ( cell. textField)
128132 if let selectionRange = capturedSelectionRange {
129133 cell. textField? . currentEditor ( ) ? . selectedRange = selectionRange
130134 }
131135 }
132- }
133-
134- // Restore selected items where the files still exist.
135- let selectedIndexes = selectedRows. compactMap ( { outlineView. row ( forItem: $0) } ) . filter ( { $0 >= 0 } )
136- controller? . shouldSendSelectionUpdate = false
137- outlineView. selectRowIndexes ( IndexSet ( selectedIndexes) , byExtendingSelection: false )
138- controller? . shouldSendSelectionUpdate = true
139-
140- // Reselect the file that is currently active in the editor so it still appears highlighted
141- if outlineView. selectedRowIndexes. isEmpty,
142- let activeFileID = workspace? . editorManager? . activeEditor. selectedTab? . file. id {
143- controller? . updateSelection ( itemID: activeFileID)
136+ } else {
137+ // Reselect the file that is currently active in the editor so it still appears highlighted
138+ if selectedIndexes. isEmpty,
139+ let activeFileID = workspace? . editorManager? . activeEditor. selectedTab? . file. id {
140+ controller? . updateSelection ( itemID: activeFileID)
141+ }
144142 }
145143 }
146144
0 commit comments