Skip to content

Commit 76bee9a

Browse files
committed
fix(CommandPalette): preserve group order in search results
Fixes an issue where command palette groups were rendered in unpredictable order instead of preserving the order defined in the groups prop. - Replace Object.entries() with groups.value iteration to maintain original order
1 parent a74879b commit 76bee9a

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/runtime/components/CommandPalette.vue

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -296,24 +296,28 @@ const filteredGroups = computed(() => {
296296
return acc
297297
}, {} as Record<string, (T & { matches?: FuseResult<T>['matches'] })[]>)
298298
299-
const fuseGroups = Object.entries(groupsById).map(([id, items]) => {
300-
const group = groups.value?.find(group => group.id === id)
301-
if (!group) {
302-
return
303-
}
304-
305-
return getGroupWithItems(group, items)
306-
}).filter(group => !!group)
307-
308-
const nonFuseGroups = groups.value
309-
?.map((group, index) => ({ ...group, index }))
310-
?.filter(group => group.ignoreFilter && group.items?.length)
311-
?.map(group => ({ ...getGroupWithItems(group, group.items || []), index: group.index })) || []
312-
313-
return nonFuseGroups.reduce((acc, group) => {
314-
acc.splice(group.index, 0, group)
315-
return acc
316-
}, [...fuseGroups])
299+
const fuseGroups
300+
= groups.value
301+
?.filter(group => !group.ignoreFilter && groupsById[group.id]?.length)
302+
?.map(group => getGroupWithItems(group, groupsById[group.id] || []))
303+
|| []
304+
305+
const nonFuseGroups
306+
= groups.value
307+
?.filter(group => group.ignoreFilter && group.items?.length)
308+
?.map(group => getGroupWithItems(group, group.items || [])) || []
309+
310+
return (
311+
groups.value
312+
?.map((originalGroup) => {
313+
if (originalGroup.ignoreFilter) {
314+
return nonFuseGroups.find(group => group.id === originalGroup.id)
315+
} else {
316+
return fuseGroups.find(group => group.id === originalGroup.id)
317+
}
318+
})
319+
.filter(group => !!group) || []
320+
)
317321
})
318322
319323
const filteredItems = computed(() => filteredGroups.value.flatMap(group => group.items || []))

0 commit comments

Comments
 (0)