Repository: CodeEditApp/CodeEdit
File: CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorViewController.swift (Swift)

Code before:
    /// Expand or collapse the folder on double click
    @objc
    private func onItemDoubleClicked() {
        guard let item = outlineView.item(atRow: outlineView.clickedRow) as? CEWorkspaceFile else { return }

        if item.isFolder {
            if outlineView.isItemExpanded(item) {
                outlineView.collapseItem(item)
            } else {
                outlineView.expandItem(item)
            }
        } else if Settings[\.navigation].navigationStyle == .openInTabs {
            workspace?.editorManager?.activeEditor.openTab(file: item, asTemporary: false)
        }
    }

    /// Get the appropriate color for the items icon depending on the users preferences.
    /// - Parameter item: The `FileItem` to get the color for
    /// - Returns: A `NSColor` for the given `FileItem`.
    private func color(for item: CEWorkspaceFile) -> NSColor {
        if !item.isFolder && iconColor == .color {
            return NSColor(item.iconColor)
        } else {
            return .secondaryLabelColor
        }
    }

    private func handleFilterChange() {
        filteredContentChildren.removeAll()
        outlineView.reloadData()

        /// If the filter is empty, show all items and restore the expanded state.
        if filter.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
            restoreExpandedState()
        } else {
            /// Expand all items for search.
            outlineView.expandItem(outlineView.item(atRow: 0), expandChildren: true)
        }

        if let root = content.first(where: { $0.isRoot }), let children = filteredContentChildren[root] {
            if children.isEmpty {
                noResultsLabel.isHidden = false
                outlineView.hideRows(at: IndexSet(integer: 0))
            } else {
                noResultsLabel.isHidden = true
            }
        }
    }

    /// Checks if the given filter matches the name of the item or any of its children.
    func fileSearchMatches(_ filter: String, for item: CEWorkspaceFile) -> Bool {

Review comment (suggestion):
One more thing for the expanded state, if the user closes the app before the expanded state can be restored, all folders will now be expanded when the user opens the app again.

We should disable expansion state restoration when the filter is active, just using `outlineView.autosaveExpandedItems = false/true`. That should make it so it only saves the last expanded state when the app is restarted and the autosave is enabled again.

Code after:
        if item.isFolder {
            if outlineView.isItemExpanded(item) {
                outlineView.collapseItem(item)
            } else {
                outlineView.expandItem(item)
            }
        } else if Settings[\.navigation].navigationStyle == .openInTabs {
            workspace?.editorManager?.activeEditor.openTab(file: item, asTemporary: false)
        }
    }

    /// Get the appropriate color for the items icon depending on the users preferences.
    /// - Parameter item: The `FileItem` to get the color for
    /// - Returns: A `NSColor` for the given `FileItem`.
    private func color(for item: CEWorkspaceFile) -> NSColor {
        if !item.isFolder && iconColor == .color {
            return NSColor(item.iconColor)
        } else {
            return .secondaryLabelColor
        }
    }

    func handleFilterChange() {
        filteredContentChildren.removeAll()
        outlineView.reloadData()

        guard let workspace else { return }

        /// If the filter is empty, show all items and restore the expanded state.
        if workspace.navigatorFilter.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
            restoreExpandedState()
            outlineView.autosaveExpandedItems = true
        } else {
            outlineView.autosaveExpandedItems = false
            /// Expand all items for search.
            outlineView.expandItem(outlineView.item(atRow: 0), expandChildren: true)
        }

        if let root = content.first(where: { $0.isRoot }), let children = filteredContentChildren[root] {
            if children.isEmpty {
                noResultsLabel.isHidden = false
                outlineView.hideRows(at: IndexSet(integer: 0))
            } else {
                noResultsLabel.isHidden = true
            }
        }
    }

    /// Checks if the given filter matches the name of the item or any of its children.
    func fileSearchMatches(_ filter: String, for item: CEWorkspaceFile) -> Bool {
        guard !filter.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { return true }