@@ -136,19 +136,35 @@ function clearSearch() {
136
136
search ( '' ) ;
137
137
}
138
138
139
- function search ( query ) {
139
+ function debounce ( func , delay ) {
140
+ let timeout ;
141
+ return function ( ) {
142
+ const context = this ;
143
+ const args = arguments ;
144
+ const later = function ( ) {
145
+ timeout = null ;
146
+ func . apply ( context , args ) ;
147
+ } ;
148
+ clearTimeout ( timeout ) ;
149
+ timeout = setTimeout ( later , delay ) ;
150
+ } ;
151
+ } ;
152
+
153
+ function searchActually ( query ) {
140
154
searchQuery = query ;
141
155
if ( ! memberFunctionsList && selectedNavTab ( ) == 'entities' ) {
142
156
fetch ( `${ FLASH_OUTPUT_URL } /functions.json` )
143
- . then ( res => res . json ( ) )
144
- . then ( res => {
145
- memberFunctionsList = res ;
146
- search ( searchQuery ) ;
147
- } ) ;
157
+ . then ( res => res . json ( ) )
158
+ . then ( res => {
159
+ memberFunctionsList = res ;
160
+ searchActually ( searchQuery ) ;
161
+ } ) ;
148
162
}
149
163
updateNav ( ) ;
150
164
}
151
165
166
+ const search = debounce ( searchActually , 50 ) ;
167
+
152
168
function getFullName ( node ) {
153
169
let parent = node ;
154
170
const result = [ node . textContent . trim ( ) ] ;
@@ -233,11 +249,14 @@ function furryMatchMany(list, query, separator) {
233
249
let score = 0 ;
234
250
let someMatched = false ;
235
251
let i = 0 ;
252
+ // hack: "::" -> ":"
253
+ const queryParts = query . split ( separator [ 0 ] ) . filter ( x => x !== "" ) ;
254
+ let queryIndex = 0 ;
236
255
for ( const item of list ) {
237
256
if ( matched . length ) {
238
257
matched += `<span class="scope">${ separator } </span>` ;
239
258
}
240
- const match = furryMatch ( item , query ) ;
259
+ const match = furryMatch ( item , queryParts [ Math . min ( queryIndex , queryParts . length - 1 ) ] ) ;
241
260
if ( match ) {
242
261
matched += match . matched ;
243
262
score += match . score ;
@@ -246,12 +265,20 @@ function furryMatchMany(list, query, separator) {
246
265
if ( i !== list . length - 1 ) {
247
266
score -= 5 ;
248
267
}
268
+ queryIndex ++ ;
269
+ if ( queryIndex >= queryParts . length ) {
270
+ score -= 5 ;
271
+ }
249
272
}
250
273
else {
251
274
matched += item ;
252
275
}
253
276
i ++ ;
254
277
}
278
+ // theres still stuff that wasnt matched
279
+ if ( queryIndex < queryParts . length ) {
280
+ someMatched = false ;
281
+ }
255
282
return someMatched ? { score, matched } : undefined ;
256
283
}
257
284
@@ -302,21 +329,19 @@ function updateNav() {
302
329
} ) ;
303
330
if ( selectedNavTab ( ) == 'entities' ) {
304
331
memberFunctionsList ?. forEach ( fun => {
305
- let f = fun . split ( '::' ) ;
306
- const name = f . pop ( ) ;
307
- const match = furryMatchMany ( [ name ] , searchQuery , '::' ) ;
332
+ let funParts = fun . split ( '::' ) ;
333
+ const name = funParts . at ( - 1 ) ;
334
+ const match = furryMatchMany ( funParts , searchQuery , '::' ) ;
308
335
if ( match ) {
336
+ funParts . pop ( ) ;
309
337
const node = document . createElement ( 'a' ) ;
310
- const url = `${ FLASH_OUTPUT_URL } /classes/${ f . join ( '/' ) } #${ name . replace ( / \s + \( [ 0 - 9 ] + \) / , '' ) } ` ;
338
+ const url = `${ FLASH_OUTPUT_URL } /classes/${ funParts . join ( '/' ) } #${ name . replace ( / \s + \( [ 0 - 9 ] + \) / , '' ) } ` ;
311
339
node . setAttribute ( 'href' , url ) ;
312
340
node . addEventListener ( 'click' , e => {
313
341
navigate ( url ) ;
314
342
e . preventDefault ( ) ;
315
343
} ) ;
316
- f = f . map ( a => `<span class="namespace">${ a } </span>` ) ;
317
- f . push ( match . matched ) ;
318
- node . innerHTML = feather . icons . code . toSvg ( { 'class' : 'icon class' } ) +
319
- f . join ( '<span class="scope">::</span>' ) ;
344
+ node . innerHTML = feather . icons . code . toSvg ( { 'class' : 'icon class' } ) + match . matched ;
320
345
results . push ( [ match . score , node ] ) ;
321
346
}
322
347
} ) ;
0 commit comments