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

Code before:

        guard let workspace else { return }

        /// If the filter is empty, show all items and restore the expanded state.
        if workspace.sourceControlFilter || !filterIsEmpty {
            outlineView.autosaveExpandedItems = false
            /// Expand all items for search.
            outlineView.expandItem(outlineView.item(atRow: 0), expandChildren: true)
        } else {
            restoreExpandedState()
            outlineView.autosaveExpandedItems = 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, sourceControlFilter: Bool) -> Bool {
        guard !(filterIsEmpty && !sourceControlFilter) else {
            return true
        }

        if sourceControlFilter {
            if item.gitStatus != nil && item.gitStatus != GitStatus.none &&
                (filterIsEmpty || item.name.localizedCaseInsensitiveContains(filter)) {
                saveAllContentChildren(for: item)
                return true
            }
        } else if item.name.localizedCaseInsensitiveContains(filter) {
            saveAllContentChildren(for: item)
            return true
        }

        if let children = workspace?.workspaceFileManager?.childrenOfFile(item) {
            return children.contains { fileSearchMatches(filter, for: $0, sourceControlFilter: sourceControlFilter) }
        }

        return false
    }

    /// Saves all children of a given folder item to the filtered content cache.
    /// This is specially useful when the name of a folder matches the search.
    /// Just like in Xcode, this shows all the content of the folder.
    private func saveAllContentChildren(for item: CEWorkspaceFile) {

Review comment (refactor):
The double negation is hard to read. Can you simplify it to: `sourceControlFilter || !filterIsEmpty`

Code after:

        guard let workspace else { return }

        /// If the filter is empty, show all items and restore the expanded state.
        if workspace.sourceControlFilter || !filterIsEmpty {
            outlineView.autosaveExpandedItems = false
            /// Expand all items for search.
            outlineView.expandItem(outlineView.item(atRow: 0), expandChildren: true)
        } else {
            restoreExpandedState()
            outlineView.autosaveExpandedItems = 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, sourceControlFilter: Bool) -> Bool {
        guard !filterIsEmpty || sourceControlFilter else {
            return true
        }

        if sourceControlFilter {
            if item.gitStatus != nil && item.gitStatus != GitStatus.none &&
                (filterIsEmpty || item.name.localizedCaseInsensitiveContains(filter)) {
                saveAllContentChildren(for: item)
                return true
            }
        } else if item.name.localizedCaseInsensitiveContains(filter) {
            saveAllContentChildren(for: item)
            return true
        }

        if let children = workspace?.workspaceFileManager?.childrenOfFile(item) {
            return children.contains { fileSearchMatches(filter, for: $0, sourceControlFilter: sourceControlFilter) }
        }

        return false
    }

    /// Saves all children of a given folder item to the filtered content cache.
    /// This is specially useful when the name of a folder matches the search.
    /// Just like in Xcode, this shows all the content of the folder.
    private func saveAllContentChildren(for item: CEWorkspaceFile) {