361361 return $scope . groups [ lint . group ] ;
362362 } ;
363363
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-
400364 $scope . byApplicabilities = function ( lint ) {
401365 return $scope . applicabilities [ lint . applicability ] ;
402366 } ;
@@ -472,6 +436,11 @@ function getQueryVariable(variable) {
472436window . searchState = {
473437 timeout : null ,
474438 inputElem : document . getElementById ( "search-input" ) ,
439+ lastSearch : '' ,
440+ clearInput : ( ) => {
441+ searchState . inputElem . value = "" ;
442+ searchState . filterLints ( ) ;
443+ } ,
475444 clearInputTimeout : ( ) => {
476445 if ( searchState . timeout !== null ) {
477446 clearTimeout ( searchState . timeout ) ;
@@ -483,32 +452,38 @@ window.searchState = {
483452 setTimeout ( searchState . filterLints , 50 ) ;
484453 } ,
485454 filterLints : ( ) => {
486- let searchStr = searchState . value . trim ( ) . toLowerCase ( ) ;
455+ searchState . clearInputTimeout ( ) ;
456+
457+ let searchStr = searchState . inputElem . value . trim ( ) . toLowerCase ( ) ;
487458 if ( searchStr . startsWith ( "clippy::" ) ) {
488459 searchStr = searchStr . slice ( 8 ) ;
489460 }
461+ if ( searchState . lastSearch === searchStr ) {
462+ return ;
463+ }
464+ searchState . lastSearch = searchStr ;
490465 const terms = searchStr . split ( " " ) ;
491466
492467 onEachLazy ( document . querySelectorAll ( "article" ) , lint => {
493468 // Search by id
494469 if ( lint . id . indexOf ( searchStr . replaceAll ( "-" , "_" ) ) !== - 1 ) {
495- el . style . display = "" ;
470+ lint . style . display = "" ;
496471 return ;
497472 }
498473 // Search the description
499474 // 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 ( ) ;
501476 for ( index = 0 ; index < terms . length ; index ++ ) {
502477 // This is more likely and will therefore be checked first
503478 if ( docsLowerCase . indexOf ( terms [ index ] ) !== - 1 ) {
504- continue ;
479+ return ;
505480 }
506481
507482 if ( lint . id . indexOf ( terms [ index ] ) !== - 1 ) {
508- continue ;
483+ return ;
509484 }
510485
511- return false ;
486+ lint . style . display = "none" ;
512487 }
513488 } ) ;
514489 } ,
@@ -631,7 +606,16 @@ function generateSettings() {
631606 ) ;
632607}
633608
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+
634617generateSettings ( ) ;
618+ generateSearch ( ) ;
635619
636620// loading the theme after the initial load
637621const prefersDark = window . matchMedia ( "(prefers-color-scheme: dark)" ) ;
0 commit comments