Closed weisJ closed 1 month ago
I think it should be possible to implement it even on Sonoma by using NSColor.findHighlightColor. The only caveat is that the selected item color is white which makes unreadable on the yellow background. Here is a quick example:
diff --git a/Maccy/Observables/HistoryItemDecorator.swift b/Maccy/Observables/HistoryItemDecorator.swift
index 5fd012c..adcb58f 100644
--- a/Maccy/Observables/HistoryItemDecorator.swift
+++ b/Maccy/Observables/HistoryItemDecorator.swift
@@ -96,14 +96,15 @@ class HistoryItemDecorator: Identifiable, Hashable {
var attributedString = AttributedString(title.shortened(to: 500))
for range in attributedString.ranges(of: query, options: .caseInsensitive) {
- switch Defaults[.highlightMatch] {
- case .italic:
- attributedString[range].font = .italic(.body)()
- case .underline:
- attributedString[range].underlineStyle = .single
- default:
- attributedString[range].font = .bold(.body)()
- }
+ attributedString[range].backgroundColor = NSColor.findHighlightColor
+// switch Defaults[.highlightMatch] {
+// case .italic:
+// attributedString[range].font = .italic(.body)()
+// case .underline:
+// attributedString[range].underlineStyle = .single
+// default:
+// attributedString[range].font = .bold(.body)()
+// }
}
The next version of macOS adds text highlighting capabilities similar to how search results are displayed in Safari, Notes etc. Maybe this could be added as an option for the search result highlighting in Maccy also.
https://developer.apple.com/documentation/foundation/nsattributedstring/texthighlightstyle