@@ -8,7 +8,9 @@ static function highlightSegments(text: string, query: string) {
88 const escaped = q .replace (/ [. *+?^${}()|[\]\\ ] / g , " \\ $&" );
99 const parts = text .split (new RegExp (` (${escaped }) ` , " gi" ));
1010 const lower = q .toLowerCase ();
11- return parts .filter (Boolean ).map ((p ) => ({ text: p , hl: p .toLowerCase () === lower }));
11+ return parts
12+ .filter (Boolean )
13+ .map ((p ) => ({ text: p , hl: p .toLowerCase () === lower }));
1214}
1315
1416export interface Input {
@@ -18,7 +20,7 @@ export interface Input {
1820
1921let /open := input .open
2022let /query = " "
21- let /results = undefined as SearchHit [] | undefined
23+ let /results = ( undefined as SearchHit [] | undefined )
2224let /activeIndex = - 1
2325
2426script --
@@ -55,10 +57,14 @@ dialog/$dialog
5557 ,onKeyDown (e ) {
5658 if (e .key === " ArrowDown" ) {
5759 e .preventDefault ();
58- if (results && results .length > 0 ) activeIndex = (activeIndex + 1 ) % results .length ;
60+ if (results && results .length > 0 ) {
61+ activeIndex = (activeIndex + 1 ) % results .length ;
62+ }
5963 } else if (e .key === " ArrowUp" ) {
6064 e .preventDefault ();
61- if (results && results .length > 0 ) activeIndex = (activeIndex - 1 + results .length ) % results .length ;
65+ if (results && results .length > 0 ) {
66+ activeIndex = (activeIndex - 1 + results .length ) % results .length ;
67+ }
6268 }
6369 }
6470 form
@@ -76,7 +82,7 @@ dialog/$dialog
7682 ,type = " text"
7783 ,placeholder = " Search docs..."
7884 ,value := query
79- if = ( results && results .length > 0 )
85+ if = results && results .length > 0
8086 div class = styles .results
8187 for |result , i | of = results
8288 a /$el
@@ -99,14 +105,18 @@ dialog/$dialog
99105 if (i === activeIndex ) {
100106 $el ().scrollIntoView ({ block: " nearest" });
101107 }
102- const /titleMatch = query .trim () && result .title .toLowerCase ().includes (query .trim ().toLowerCase ())
103- const /displayText = titleMatch ? result .title : (result .snippet || result .title )
108+ const /titleMatch= (
109+ query .trim () &&
110+ result .title .toLowerCase ().includes (query .trim ().toLowerCase ())
111+ )
112+ const /displayText= (
113+ titleMatch ? result .title : result .snippet || result .title
114+ )
104115 span class = styles .displayText
105116 for | seg | of = highlightSegments (displayText , query )
106- if = ( seg .hl )
117+ if = seg .hl
107118 mark class = styles .highlight -- $ { seg . text }
108- else
109- -- ${seg .text }
119+ else -- ${seg .text }
110120 span class = styles .breadcrumbs -- ${result .breadcrumbs .join (" · " ) }
111- else if = ( query .trim () && results )
121+ else if = query .trim () && results
112122 div class = styles .empty -- No results found.
0 commit comments