@@ -46,55 +46,45 @@ class FileSystemTableViewCell: StandardTableViewCell {
46
46
imageView? . contentTintColor = color ( for: item)
47
47
48
48
let fileName = item. labelFileName ( )
49
+ let fontSize = textField? . font? . pointSize ?? 12
49
50
50
- guard let navigatorFilter else {
51
+ guard let filter = navigatorFilter? . trimmingCharacters ( in : . whitespacesAndNewlines ) , !filter . isEmpty else {
51
52
textField? . stringValue = fileName
52
53
return
53
54
}
54
55
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) ,
94
73
. 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)
96
84
)
97
85
}
86
+
87
+ textField? . attributedStringValue = attributedString
98
88
}
99
89
100
90
func addModel( ) {
0 commit comments