@@ -46,55 +46,45 @@ class FileSystemTableViewCell: StandardTableViewCell {
4646 imageView? . contentTintColor = color ( for: item)
4747
4848 let fileName = item. labelFileName ( )
49+ let fontSize = textField? . font? . pointSize ?? 12
4950
50- guard let navigatorFilter else {
51+ guard let filter = navigatorFilter? . trimmingCharacters ( in : . whitespacesAndNewlines ) , !filter . isEmpty else {
5152 textField? . stringValue = fileName
5253 return
5354 }
5455
55- // Apply bold style if the filename matches the workspace filter
56- if !navigatorFilter. trimmingCharacters ( in: . whitespacesAndNewlines) . isEmpty {
57- let attributedString = NSMutableAttributedString ( string: fileName)
58-
59- // Check if the filename contains the filter text
60- let range = NSString ( string: fileName) . range ( of: navigatorFilter, options: . caseInsensitive)
61- if range. location != NSNotFound {
62- // Set the label color to secondary
63- attributedString. addAttribute (
64- . foregroundColor,
65- value: NSColor . secondaryLabelColor,
66- range: NSRange ( location: 0 , length: attributedString. length)
67- )
68-
69- // If the filter text matches, bold the matching text and set primary label color
70- attributedString. addAttributes (
71- [
72- . font: NSFont . boldSystemFont ( ofSize: textField? . font? . pointSize ?? 12 ) ,
73- . foregroundColor: NSColor . labelColor
74- ] ,
75- range: range
76- )
77- } else {
78- // If no match, apply primary label color for parent folder,
79- // or secondary label color for a non-matching file
80- attributedString. addAttribute (
81- . foregroundColor,
82- value: item. isFolder ? NSColor . labelColor : NSColor . secondaryLabelColor,
83- range: NSRange ( location: 0 , length: attributedString. length)
84- )
85- }
86-
87- textField? . attributedStringValue = attributedString
88- } else {
89- // If no filter is applied, reset to normal font and primary label color
90- textField? . attributedStringValue = NSAttributedString (
91- string: fileName,
92- attributes: [
93- . font: NSFont . systemFont ( ofSize: textField? . font? . pointSize ?? 12 ) ,
56+ let paragraphStyle = NSMutableParagraphStyle ( )
57+ paragraphStyle. lineBreakMode = . byTruncatingMiddle
58+
59+ /// Initialize default attributes
60+ let attributedString = NSMutableAttributedString ( string: fileName, attributes: [
61+ . paragraphStyle: paragraphStyle,
62+ . font: NSFont . systemFont ( ofSize: fontSize) ,
63+ . foregroundColor: NSColor . secondaryLabelColor
64+ ] )
65+
66+ /// Check if the filename contains the filter text
67+ let range = ( fileName as NSString ) . range ( of: filter, options: . caseInsensitive)
68+ if range. location != NSNotFound {
69+ /// If the filter text matches, bold the matching text and set primary label color
70+ attributedString. addAttributes (
71+ [
72+ . font: NSFont . boldSystemFont ( ofSize: fontSize) ,
9473 . foregroundColor: NSColor . labelColor
95- ]
74+ ] ,
75+ range: range
76+ )
77+ } else {
78+ /// If no match, apply primary label color for parent folder,
79+ /// or secondary label color for a non-matching file
80+ attributedString. addAttribute (
81+ . foregroundColor,
82+ value: item. isFolder ? NSColor . labelColor : NSColor . secondaryLabelColor,
83+ range: NSRange ( location: 0 , length: attributedString. length)
9684 )
9785 }
86+
87+ textField? . attributedStringValue = attributedString
9888 }
9989
10090 func addModel( ) {
0 commit comments