@@ -92,6 +92,13 @@ function commandScore(command: PaletteCommand, query: string): number {
9292 return best ;
9393}
9494
95+ function sortByCommandScore (
96+ commands : ReadonlyArray < PaletteCommand > ,
97+ query : string ,
98+ ) : PaletteCommand [ ] {
99+ return commands . toSorted ( ( a , b ) => commandScore ( b , query ) - commandScore ( a , query ) ) ;
100+ }
101+
95102// ── Command palette component ───────────────────────────────────────
96103
97104export function CommandPalette ( ) {
@@ -344,9 +351,10 @@ function CommandsView() {
344351 // Filter commands by query
345352 const filtered = useMemo ( ( ) => {
346353 if ( query . length === 0 ) return commands ;
347- return commands
348- . filter ( ( cmd ) => commandMatchesQuery ( cmd , query ) )
349- . toSorted ( ( a , b ) => commandScore ( b , query ) - commandScore ( a , query ) ) ;
354+ return sortByCommandScore (
355+ commands . filter ( ( cmd ) => commandMatchesQuery ( cmd , query ) ) ,
356+ query ,
357+ ) ;
350358 } , [ commands , query ] ) ;
351359
352360 // Group filtered commands
@@ -492,7 +500,7 @@ function ProjectsView() {
492500 ? projects . filter ( ( p ) => fuzzyMatch ( query , p . name ) || fuzzyMatch ( query , p . cwd ) )
493501 : projects ;
494502
495- return [ ... filtered ] . toSorted ( ( a , b ) => {
503+ return filtered . toSorted ( ( a , b ) => {
496504 const aIndex = mruProjectIds . indexOf ( a . id ) ;
497505 const bIndex = mruProjectIds . indexOf ( b . id ) ;
498506 if ( aIndex >= 0 && bIndex >= 0 ) return aIndex - bIndex ;
0 commit comments