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

Code before:
    ///   - frameRect: The frame of the cell.
    ///   - item: The file item the cell represents.
    ///   - isEditable: Set to true if the user should be able to edit the file name.
    init(frame frameRect: NSRect, item: CEWorkspaceFile?, isEditable: Bool = true, workspace: WorkspaceDocument?) {
        super.init(frame: frameRect, isEditable: isEditable, workspace: workspace)

        if let item = item {
            addIcon(item: item)
        }
        addModel()
    }

    override func configLabel(label: NSTextField, isEditable: Bool) {
        super.configLabel(label: label, isEditable: isEditable)
        label.delegate = self
    }

    func addIcon(item: CEWorkspaceFile) {
        fileItem = item
        imageView?.image = item.nsIcon
        imageView?.contentTintColor = color(for: item)

        let fileName = item.labelFileName()

        // Apply bold style if the filename matches the workspace filter
        if let filter = workspace?.filter, !filter.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
            let attributedString = NSMutableAttributedString(string: fileName)

            // Check if the filename contains the filter text
            let range = NSString(string: fileName).range(of: filter, options: .caseInsensitive)
            if range.location != NSNotFound {
                // Set the label color to secondary
                attributedString.addAttribute(
                    .foregroundColor,
                    value: NSColor.secondaryLabelColor,
                    range: NSRange(location: 0, length: attributedString.length)
                )

                // If the filter text matches, bold the matching text and set primary label color
                attributedString.addAttributes(
                    [
                        .font: NSFont.boldSystemFont(ofSize: textField?.font?.pointSize ?? 12),
                        .foregroundColor: NSColor.textColor
                    ],
                    range: range
                )
            } else {
                // If no match, apply primary label color for parent folder,
                // or secondary label color for a non-matching file
                attributedString.addAttribute(
                    .foregroundColor,

Review comment (suggestion):
This cell class is used outside of the project navigator. Instead of grabbing the filter from the workspace, lets add an optional filter property and set it from the project navigator. That'll prevent the filter style from leaking into other UI elements like the search list.

Code after:
    /// - Parameters:
    ///   - frameRect: The frame of the cell.
    ///   - item: The file item the cell represents.
    ///   - isEditable: Set to true if the user should be able to edit the file name.
    ///   - navigatorFilter: An optional string use to filter the navigator area.
    ///                      (Used for bolding and changing primary/secondary color).
    init(frame frameRect: NSRect, item: CEWorkspaceFile?, isEditable: Bool = true, navigatorFilter: String? = nil) {
        super.init(frame: frameRect, isEditable: isEditable)
        self.navigatorFilter = navigatorFilter

        if let item = item {
            addIcon(item: item)
        }
        addModel()
    }

    override func configLabel(label: NSTextField, isEditable: Bool) {
        super.configLabel(label: label, isEditable: isEditable)
        label.delegate = self
    }

    func addIcon(item: CEWorkspaceFile) {
        fileItem = item
        imageView?.image = item.nsIcon
        imageView?.contentTintColor = color(for: item)

        let fileName = item.labelFileName()

        guard let navigatorFilter else {
            textField?.stringValue = fileName
            return
        }

        // Apply bold style if the filename matches the workspace filter
        if !navigatorFilter.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
            let attributedString = NSMutableAttributedString(string: fileName)

            // Check if the filename contains the filter text
            let range = NSString(string: fileName).range(of: navigatorFilter, options: .caseInsensitive)
            if range.location != NSNotFound {
                // Set the label color to secondary
                attributedString.addAttribute(
                    .foregroundColor,
                    value: NSColor.secondaryLabelColor,
                    range: NSRange(location: 0, length: attributedString.length)
                )

                // If the filter text matches, bold the matching text and set primary label color
                attributedString.addAttributes(
                    [
                        .font: NSFont.boldSystemFont(ofSize: textField?.font?.pointSize ?? 12),