@@ -109,53 +109,80 @@ export class Launcher extends search.Search {
109
109
// Filter matching desktop apps
110
110
for ( const [ where , app ] of this . desktop_apps ) {
111
111
const name = app . name ( )
112
- const name_match = name . toLowerCase ( )
113
- const retain = name_match . startsWith ( pattern )
114
- || name_match . includes ( pattern )
115
- || levenshtein . compare ( name_match , pattern ) < 3
116
-
117
- if ( retain ) {
118
- const generic = app . generic_name ( ) ;
119
-
120
- const button = new launch . SearchOption (
121
- name ,
122
- generic ? generic + " — " + where : where ,
123
- 'application-default-symbolic' ,
124
- { gicon : app . icon ( ) } ,
125
- this . icon_size ( ) ,
126
- { app }
127
- )
112
+ const keywords = app . keywords ( )
113
+ const app_items = keywords !== null ? name . split ( ) . concat ( keywords ) : [ name ]
114
+
115
+ for ( const item of app_items ) {
116
+ const item_match = item . toLowerCase ( )
117
+ if ( item_match . startsWith ( pattern )
118
+ || item_match . includes ( pattern )
119
+ || levenshtein . compare ( item_match , pattern ) < 3 {
120
+ const generic = app . generic_name ( ) ;
121
+ const button = new launch . SearchOption (
122
+ name ,
123
+ generic ? generic + " — " + where : where ,
124
+ 'application-default-symbolic' ,
125
+ { gicon : app . icon ( ) } ,
126
+ this . icon_size ( ) ,
127
+ { app } ,
128
+ keywords
129
+ )
128
130
129
- DedicatedGPU . addPopup ( app , button . widget )
131
+ DedicatedGPU . addPopup ( app , button . widget )
130
132
131
- this . options . push ( button )
133
+ this . options . push ( button )
134
+ break
135
+ }
132
136
}
133
137
}
134
138
135
139
const sorter = ( a : launch . SearchOption , b : launch . SearchOption ) => {
136
140
const a_name = a . title . toLowerCase ( )
137
141
const b_name = b . title . toLowerCase ( )
138
142
139
- let a_name_weight = 0 , b_name_weight = 0 ;
143
+ let a_weight = 0 , b_weight = 0 ;
140
144
141
145
if ( ! a_name . startsWith ( pattern ) ) {
142
- a_name_weight = levenshtein . compare ( a_name , pattern )
143
- if ( a . description ) {
144
- a_name_weight = Math . min ( a_name_weight , levenshtein . compare ( pattern , a . description . toLowerCase ( ) ) )
146
+ a_weight = 1
147
+ if ( ! a_name . includes ( pattern ) {
148
+ a_weight = levenshtein . compare ( a_name , pattern )
149
+ if ( a . description ) {
150
+ a_weight = Math . min ( a_weight , levenshtein . compare ( pattern , a . description . toLowerCase ( ) ) )
151
+ }
152
+ if ( a . keywords ) {
153
+ for ( const keyword of a . keywords ) {
154
+ if keyword . toLowerCase ( ) . startsWith ( pattern ) || keyword . toLowerCase ( ) . includes ( pattern ) {
155
+ a_weight = 1
156
+ } else {
157
+ a_weight = Math . min ( a_weight , ( levenshtein . compare ( pattern , keyword . toLowerCase ( ) ) + 1 ) )
158
+ }
159
+ }
160
+ }
145
161
}
146
162
}
147
163
148
164
if ( ! b_name . startsWith ( pattern ) ) {
149
- b_name_weight = levenshtein . compare ( b_name , pattern )
150
-
151
- if ( b . description ) {
152
- b_name_weight = Math . min ( b_name_weight , levenshtein . compare ( pattern , b . description . toLowerCase ( ) ) )
165
+ b_weight = 1
166
+ if ( ! b_name . includes ( pattern ) ) {
167
+ b_weight = levenshtein . compare ( b_name , pattern )
168
+ if ( b . description ) {
169
+ b_weight = Math . min ( b_weight , levenshtein . compare ( pattern , b . description . toLowerCase ( ) ) )
170
+ }
171
+ if ( b . keywords ) {
172
+ for ( const keyword of b . keywords ) {
173
+ if keyword . toLowerCase ( ) . startsWith ( pattern ) || keyword . toLowerCase ( ) . includes ( pattern ) {
174
+ b_weight = 1
175
+ } else {
176
+ b_weight = Math . min ( b_weight , ( levenshtein . compare ( pattern , keyword . toLowerCase ( ) ) + 1 ) )
177
+ }
178
+ }
179
+ }
153
180
}
154
181
}
155
182
156
- return a_name_weight === b_name_weight
183
+ return a_weight === b_weight
157
184
? a_name . length > b_name . length ? 1 : 0
158
- : a_name_weight > b_name_weight ? 1 : 0
185
+ : a_weight > b_weight ? 1 : 0
159
186
}
160
187
161
188
// Sort the list of matched selections
0 commit comments