diff --git a/CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorResultList/FindNavigatorListViewController.swift b/CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorResultList/FindNavigatorListViewController.swift index f469de2ee..c377269c9 100644 --- a/CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorResultList/FindNavigatorListViewController.swift +++ b/CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorResultList/FindNavigatorListViewController.swift @@ -165,7 +165,7 @@ extension FindNavigatorListViewController: NSOutlineViewDelegate { func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? { guard let tableColumn else { return nil } if let item = item as? SearchResultMatchModel { - let frameRect = NSRect(x: 0, y: 0, width: tableColumn.width, height: CGFloat.greatestFiniteMagnitude) + let frameRect = NSRect(x: 0, y: 0, width: tableColumn.width, height: outlineView.rowHeight) return FindNavigatorListMatchCell(frame: frameRect, matchItem: item) } else { let frameRect = NSRect( diff --git a/CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorResultList/FindNavigatorMatchListCell.swift b/CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorResultList/FindNavigatorMatchListCell.swift index ec16482da..1f60f23bb 100644 --- a/CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorResultList/FindNavigatorMatchListCell.swift +++ b/CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorResultList/FindNavigatorMatchListCell.swift @@ -20,7 +20,7 @@ final class FindNavigatorListMatchCell: NSTableCellView { x: frame.origin.x, y: frame.origin.y, width: frame.width, - height: CGFloat.greatestFiniteMagnitude + height: frame.height )) // Create the label diff --git a/CodeEdit/Features/NavigatorArea/OutlineView/FileSystemTableViewCell.swift b/CodeEdit/Features/NavigatorArea/OutlineView/FileSystemTableViewCell.swift index 2388532bc..9b07702a4 100644 --- a/CodeEdit/Features/NavigatorArea/OutlineView/FileSystemTableViewCell.swift +++ b/CodeEdit/Features/NavigatorArea/OutlineView/FileSystemTableViewCell.swift @@ -46,55 +46,45 @@ class FileSystemTableViewCell: StandardTableViewCell { imageView?.contentTintColor = color(for: item) let fileName = item.labelFileName() + let fontSize = textField?.font?.pointSize ?? 12 - guard let navigatorFilter else { + guard let filter = navigatorFilter?.trimmingCharacters(in: .whitespacesAndNewlines), !filter.isEmpty 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), -.foregroundColor: NSColor.labelColor - ], - 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, - value: item.isFolder ? NSColor.labelColor : NSColor.secondaryLabelColor, - range: NSRange(location: 0, length: attributedString.length) - ) - } - - textField?.attributedStringValue = attributedString - } else { - // If no filter is applied, reset to normal font and primary label color - textField?.attributedStringValue = NSAttributedString( - string: fileName, - attributes: [ - .font: NSFont.systemFont(ofSize: textField?.font?.pointSize ?? 12), + let paragraphStyle = NSMutableParagraphStyle() + paragraphStyle.lineBreakMode = .byTruncatingMiddle + + /// Initialize default attributes + let attributedString = NSMutableAttributedString(string: fileName, attributes: [ + .paragraphStyle: paragraphStyle, + .font: NSFont.systemFont(ofSize: fontSize), + .foregroundColor: NSColor.secondaryLabelColor + ]) + + /// Check if the filename contains the filter text + let range = (fileName as NSString).range(of: filter, options: .caseInsensitive) + if range.location != NSNotFound { + /// If the filter text matches, bold the matching text and set primary label color + attributedString.addAttributes( + [ + .font: NSFont.boldSystemFont(ofSize: fontSize), .foregroundColor: NSColor.labelColor - ] + ], + 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, + value: item.isFolder ? NSColor.labelColor : NSColor.secondaryLabelColor, + range: NSRange(location: 0, length: attributedString.length) ) } + + textField?.attributedStringValue = attributedString } func addModel() {