@@ -34,6 +34,12 @@ export interface SearchableSelectItem extends SelectItem {
3434 */
3535export class SearchableSelectList implements Component , Focusable {
3636 private items : SearchableSelectItem [ ] ;
37+ private preparedItems ?: Array < {
38+ item : SearchableSelectItem ;
39+ label : string ;
40+ description : string ;
41+ searchText : string ;
42+ } > ;
3743 private filteredItems : SearchableSelectItem [ ] ;
3844 private selectedIndex = 0 ;
3945 private maxVisible : number ;
@@ -103,35 +109,35 @@ export class SearchableSelectList implements Component, Focusable {
103109 const scoredItems : ScoredItem [ ] = [ ] ;
104110 const fuzzyCandidates : FuzzyCandidate [ ] = [ ] ;
105111
106- for ( const item of this . items ) {
107- const rawLabel = this . getItemLabel ( item ) ;
108- const rawDesc = item . description ?? "" ;
109- const label = normalizeLowercaseStringOrEmpty ( stripAnsi ( rawLabel ) ) ;
110- const desc = normalizeLowercaseStringOrEmpty ( stripAnsi ( rawDesc ) ) ;
111-
112+ // Rows are fixed for the overlay lifetime; defer search projection until it is needed.
113+ this . preparedItems ??= this . items . map ( ( item ) => {
114+ const label = stripAnsi ( this . getItemLabel ( item ) ) ;
115+ const description = stripAnsi ( item . description ?? "" ) ;
116+ const searchText = stripAnsi ( item . searchText ?? "" ) ;
117+ return {
118+ item,
119+ label : normalizeLowercaseStringOrEmpty ( label ) ,
120+ description : normalizeLowercaseStringOrEmpty ( description ) ,
121+ searchText : normalizeLowercaseStringOrEmpty (
122+ [ label , description , searchText ] . filter ( ( value ) => value . length > 0 ) . join ( " " ) ,
123+ ) ,
124+ } ;
125+ } ) ;
126+ for ( const prepared of this . preparedItems ) {
112127 // Tier 1: Exact substring in label
113- const labelIndex = label . indexOf ( q ) ;
128+ const labelIndex = prepared . label . indexOf ( q ) ;
114129 if ( labelIndex !== - 1 ) {
115- scoredItems . push ( { item, tier : 0 , score : labelIndex } ) ;
130+ scoredItems . push ( { item : prepared . item , tier : 0 , score : labelIndex } ) ;
116131 continue ;
117132 }
118133 // Tier 2: Exact substring in description
119- const descIndex = desc . indexOf ( q ) ;
134+ const descIndex = prepared . description . indexOf ( q ) ;
120135 if ( descIndex !== - 1 ) {
121- scoredItems . push ( { item, tier : 1 , score : descIndex } ) ;
136+ scoredItems . push ( { item : prepared . item , tier : 1 , score : descIndex } ) ;
122137 continue ;
123138 }
124139 // Tier 3: Fuzzy match
125- const searchText = item . searchText ?? "" ;
126- fuzzyCandidates . push ( {
127- item,
128- searchText : normalizeLowercaseStringOrEmpty (
129- [ rawLabel , rawDesc , searchText ]
130- . map ( ( value ) => stripAnsi ( value ) )
131- . filter ( ( value ) => value . length > 0 )
132- . join ( " " ) ,
133- ) ,
134- } ) ;
140+ fuzzyCandidates . push ( prepared ) ;
135141 }
136142
137143 scoredItems . sort ( this . compareByScore ) ;
0 commit comments