@@ -85,7 +85,9 @@ function createHighlightedText(
85
85
if ( range . start > lastEnd + 1 ) {
86
86
const beforeText = text . slice ( lastEnd + 1 , range . start ) ;
87
87
if ( beforeText ) {
88
- fragment . appendChild ( document . createTextNode ( beforeText ) ) ;
88
+ // Wrap text nodes in span to ensure proper display in flex containers
89
+ const textSpan = createSpan ( { text : beforeText } ) ;
90
+ fragment . appendChild ( textSpan ) ;
89
91
}
90
92
}
91
93
@@ -106,7 +108,9 @@ function createHighlightedText(
106
108
if ( lastEnd + 1 < text . length ) {
107
109
const remainingText = text . slice ( lastEnd + 1 ) ;
108
110
if ( remainingText ) {
109
- fragment . appendChild ( document . createTextNode ( remainingText ) ) ;
111
+ // Wrap text nodes in span to ensure proper display in flex containers
112
+ const textSpan = createSpan ( { text : remainingText } ) ;
113
+ fragment . appendChild ( textSpan ) ;
110
114
}
111
115
}
112
116
@@ -145,12 +149,23 @@ function createItemDiv(
145
149
: item . file . basename ;
146
150
147
151
// Find relevant match results for title highlighting
148
- const titleMatchResults = item . matchResults . filter (
149
- ( result ) =>
150
- result . type === "name" ||
151
- result . type === "prefix-name" ||
152
- result . type === "fuzzy-name" ,
153
- ) ;
152
+ // When showing alias as title, use alias match results
153
+ // When showing file name as title, use only file name match results (not alias matches)
154
+ const titleMatchResults = shouldShowAliasAsTitle
155
+ ? item . matchResults . filter (
156
+ ( result ) =>
157
+ ( result . type === "name" ||
158
+ result . type === "prefix-name" ||
159
+ result . type === "fuzzy-name" ) &&
160
+ result . alias ,
161
+ )
162
+ : item . matchResults . filter (
163
+ ( result ) =>
164
+ ( result . type === "name" ||
165
+ result . type === "prefix-name" ||
166
+ result . type === "fuzzy-name" ) &&
167
+ ! result . alias ,
168
+ ) ;
154
169
155
170
const titleDiv = createDiv ( {
156
171
cls : [
@@ -299,6 +314,10 @@ function createDescriptionDiv(args: {
299
314
linkResultsNum : number ;
300
315
headerResultsNum : number ;
301
316
options : Options ;
317
+ aliasMatchDetails : {
318
+ alias : string ;
319
+ ranges : { start : number ; end : number } [ ] ;
320
+ } [ ] ;
302
321
} ) : Elements [ "descriptionDiv" ] {
303
322
const {
304
323
item,
@@ -309,6 +328,7 @@ function createDescriptionDiv(args: {
309
328
linkResultsNum,
310
329
headerResultsNum,
311
330
options,
331
+ aliasMatchDetails,
312
332
} = args ;
313
333
314
334
const descriptionDiv = createDiv ( {
@@ -328,7 +348,25 @@ function createDescriptionDiv(args: {
328
348
cls : "another-quick-switcher__item__description__alias" ,
329
349
} ) ;
330
350
aliasSpan . insertAdjacentHTML ( "beforeend" , ALIAS ) ;
331
- aliasSpan . appendText ( x ) ;
351
+
352
+ // Find matching ranges for this specific alias using allAliasRanges
353
+ const ranges : { start : number ; end : number } [ ] = [ ] ;
354
+
355
+ // Collect all ranges for this specific alias from allAliasRanges
356
+ for ( const result of item . matchResults ) {
357
+ if ( result . allAliasRanges ) {
358
+ for ( const aliasRange of result . allAliasRanges ) {
359
+ if ( aliasRange . alias === x ) {
360
+ ranges . push ( ...aliasRange . ranges ) ;
361
+ }
362
+ }
363
+ }
364
+ }
365
+
366
+ // Apply highlighting using createHighlightedText
367
+ const highlightedContent = createHighlightedText ( x , ranges ) ;
368
+ aliasSpan . appendChild ( highlightedContent ) ;
369
+
332
370
aliasDiv . appendChild ( aliasSpan ) ;
333
371
}
334
372
descriptionDiv . appendChild ( aliasDiv ) ;
@@ -454,6 +492,14 @@ export function createElements(
454
492
headerResults . flatMap ( ( xs ) => uniq ( xs . meta ?? [ ] ) ) ,
455
493
) ;
456
494
495
+ // Extract alias match details for highlighting in description
496
+ const aliasMatchDetails : {
497
+ alias : string ;
498
+ ranges : { start : number ; end : number } [ ] ;
499
+ } [ ] = item . matchResults
500
+ . filter ( ( result ) => result . allAliasRanges )
501
+ . flatMap ( ( result ) => result . allAliasRanges ! ) ;
502
+
457
503
const descriptionDiv =
458
504
aliases . length !== 0 ||
459
505
tags . length !== 0 ||
@@ -468,6 +514,7 @@ export function createElements(
468
514
linkResultsNum,
469
515
headerResultsNum,
470
516
options,
517
+ aliasMatchDetails,
471
518
} )
472
519
: undefined ;
473
520
0 commit comments