@@ -43,15 +43,19 @@ struct QuickActionsView: View {
4343 }
4444
4545 var body : some View {
46- SearchPanelView < SearchResultLabel , EmptyView , Command > (
46+ SearchPanelView < QuickSearchResultLabel , EmptyView , Command > (
4747 title: " Commands " ,
4848 image: Image ( systemName: " magnifyingglass " ) ,
4949 options: $state. filteredCommands,
5050 text: $state. commandQuery,
5151 alwaysShowOptions: true ,
5252 optionRowHeight: 30
5353 ) { command in
54- SearchResultLabel ( labelName: command. title, textToMatch: state. commandQuery)
54+ QuickSearchResultLabel (
55+ labelName: command. title,
56+ charactersToHighlight: [ ] ,
57+ nsLabelName: state. highlight ( command. title)
58+ )
5559 } onRowClick: { command in
5660 callHandler ( command: command)
5761 } onClose: {
@@ -62,47 +66,3 @@ struct QuickActionsView: View {
6266 }
6367 }
6468}
65-
66- /// Implementation of command palette entity. While swiftui does not allow to use NSMutableAttributeStrings,
67- /// the only way to fallback to UIKit and have NSViewRepresentable to be a bridge between UIKit and SwiftUI.
68- /// Highlights currently entered text query
69-
70- struct SearchResultLabel : NSViewRepresentable {
71-
72- var labelName : String
73- var textToMatch : String
74-
75- public func makeNSView( context: Context ) -> some NSTextField {
76- let label = NSTextField ( wrappingLabelWithString: labelName)
77- label. translatesAutoresizingMaskIntoConstraints = false
78- label. drawsBackground = false
79- label. textColor = . labelColor
80- label. isEditable = false
81- label. isSelectable = false
82- label. font = . labelFont( ofSize: 13 )
83- label. allowsDefaultTighteningForTruncation = false
84- label. cell? . truncatesLastVisibleLine = true
85- label. cell? . wraps = true
86- label. maximumNumberOfLines = 1
87- label. attributedStringValue = highlight ( )
88- return label
89- }
90-
91- func highlight( ) -> NSAttributedString {
92- let attribText = NSMutableAttributedString ( string: self . labelName)
93- let range : NSRange = attribText. mutableString. range (
94- of: self . textToMatch,
95- options: NSString . CompareOptions. caseInsensitive
96- )
97- attribText. addAttribute ( . foregroundColor, value: NSColor ( Color ( . labelColor) ) , range: range)
98- attribText. addAttribute ( . font, value: NSFont . boldSystemFont ( ofSize: NSFont . systemFontSize) , range: range)
99-
100- return attribText
101- }
102-
103- func updateNSView( _ nsView: NSViewType , context: Context ) {
104- nsView. textColor = textToMatch. isEmpty ? . labelColor : . secondaryLabelColor
105- nsView. attributedStringValue = highlight ( )
106- }
107-
108- }
0 commit comments