361
361
return $scope . groups [ lint . group ] ;
362
362
} ;
363
363
364
- $scope . bySearch = function ( lint , index , array ) {
365
- let searchStr = $scope . search ;
366
- // It can be `null` I haven't missed this value
367
- if ( searchStr == null ) {
368
- return true ;
369
- }
370
- searchStr = searchStr . toLowerCase ( ) ;
371
- if ( searchStr . startsWith ( "clippy::" ) ) {
372
- searchStr = searchStr . slice ( 8 ) ;
373
- }
374
-
375
- // Search by id
376
- if ( lint . id . indexOf ( searchStr . replaceAll ( "-" , "_" ) ) !== - 1 ) {
377
- return true ;
378
- }
379
-
380
- // Search the description
381
- // The use of `for`-loops instead of `foreach` enables us to return early
382
- const terms = searchStr . split ( " " ) ;
383
- const docsLowerCase = lint . docs . toLowerCase ( ) ;
384
- for ( index = 0 ; index < terms . length ; index ++ ) {
385
- // This is more likely and will therefore be checked first
386
- if ( docsLowerCase . indexOf ( terms [ index ] ) !== - 1 ) {
387
- continue ;
388
- }
389
-
390
- if ( lint . id . indexOf ( terms [ index ] ) !== - 1 ) {
391
- continue ;
392
- }
393
-
394
- return false ;
395
- }
396
-
397
- return true ;
398
- }
399
-
400
364
$scope . byApplicabilities = function ( lint ) {
401
365
return $scope . applicabilities [ lint . applicability ] ;
402
366
} ;
@@ -472,6 +436,11 @@ function getQueryVariable(variable) {
472
436
window . searchState = {
473
437
timeout : null ,
474
438
inputElem : document . getElementById ( "search-input" ) ,
439
+ lastSearch : '' ,
440
+ clearInput : ( ) => {
441
+ searchState . inputElem . value = "" ;
442
+ searchState . filterLints ( ) ;
443
+ } ,
475
444
clearInputTimeout : ( ) => {
476
445
if ( searchState . timeout !== null ) {
477
446
clearTimeout ( searchState . timeout ) ;
@@ -483,32 +452,38 @@ window.searchState = {
483
452
setTimeout ( searchState . filterLints , 50 ) ;
484
453
} ,
485
454
filterLints : ( ) => {
486
- let searchStr = searchState . value . trim ( ) . toLowerCase ( ) ;
455
+ searchState . clearInputTimeout ( ) ;
456
+
457
+ let searchStr = searchState . inputElem . value . trim ( ) . toLowerCase ( ) ;
487
458
if ( searchStr . startsWith ( "clippy::" ) ) {
488
459
searchStr = searchStr . slice ( 8 ) ;
489
460
}
461
+ if ( searchState . lastSearch === searchStr ) {
462
+ return ;
463
+ }
464
+ searchState . lastSearch = searchStr ;
490
465
const terms = searchStr . split ( " " ) ;
491
466
492
467
onEachLazy ( document . querySelectorAll ( "article" ) , lint => {
493
468
// Search by id
494
469
if ( lint . id . indexOf ( searchStr . replaceAll ( "-" , "_" ) ) !== - 1 ) {
495
- el . style . display = "" ;
470
+ lint . style . display = "" ;
496
471
return ;
497
472
}
498
473
// Search the description
499
474
// The use of `for`-loops instead of `foreach` enables us to return early
500
- const docsLowerCase = lint . docs . toLowerCase ( ) ;
475
+ const docsLowerCase = lint . textContent . toLowerCase ( ) ;
501
476
for ( index = 0 ; index < terms . length ; index ++ ) {
502
477
// This is more likely and will therefore be checked first
503
478
if ( docsLowerCase . indexOf ( terms [ index ] ) !== - 1 ) {
504
- continue ;
479
+ return ;
505
480
}
506
481
507
482
if ( lint . id . indexOf ( terms [ index ] ) !== - 1 ) {
508
- continue ;
483
+ return ;
509
484
}
510
485
511
- return false ;
486
+ lint . style . display = "none" ;
512
487
}
513
488
} ) ;
514
489
} ,
@@ -631,7 +606,16 @@ function generateSettings() {
631
606
) ;
632
607
}
633
608
609
+ function generateSearch ( ) {
610
+ searchState . inputElem . addEventListener ( "change" , handleInputChanged ) ;
611
+ searchState . inputElem . addEventListener ( "input" , handleInputChanged ) ;
612
+ searchState . inputElem . addEventListener ( "keydown" , handleInputChanged ) ;
613
+ searchState . inputElem . addEventListener ( "keyup" , handleInputChanged ) ;
614
+ searchState . inputElem . addEventListener ( "paste" , handleInputChanged ) ;
615
+ }
616
+
634
617
generateSettings ( ) ;
618
+ generateSearch ( ) ;
635
619
636
620
// loading the theme after the initial load
637
621
const prefersDark = window . matchMedia ( "(prefers-color-scheme: dark)" ) ;
0 commit comments