Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Navigator Area Label Truncation #1912

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading