Skip to content

Commit 8fe1b28

Browse files
authored
Fix Navigator Area Label Truncation (#1912)
- Adjusted logic for labels within the Navigator Area so that they truncate properly in all areas - Resolved an invalid frame error related to the height when using the search feature
1 parent 4f9505c commit 8fe1b28

File tree

3 files changed

+33
-43
lines changed

3 files changed

+33
-43
lines changed

CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorResultList/FindNavigatorListViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ extension FindNavigatorListViewController: NSOutlineViewDelegate {
165165
func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
166166
guard let tableColumn else { return nil }
167167
if let item = item as? SearchResultMatchModel {
168-
let frameRect = NSRect(x: 0, y: 0, width: tableColumn.width, height: CGFloat.greatestFiniteMagnitude)
168+
let frameRect = NSRect(x: 0, y: 0, width: tableColumn.width, height: outlineView.rowHeight)
169169
return FindNavigatorListMatchCell(frame: frameRect, matchItem: item)
170170
} else {
171171
let frameRect = NSRect(

CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorResultList/FindNavigatorMatchListCell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ final class FindNavigatorListMatchCell: NSTableCellView {
2020
x: frame.origin.x,
2121
y: frame.origin.y,
2222
width: frame.width,
23-
height: CGFloat.greatestFiniteMagnitude
23+
height: frame.height
2424
))
2525

2626
// Create the label

CodeEdit/Features/NavigatorArea/OutlineView/FileSystemTableViewCell.swift

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)