Skip to content

Commit 6507c8d

Browse files
fix: command palette providers with duplicate name (#647)
1 parent 706964e commit 6507c8d

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

packages/ui/src/lib/internal/CommandPaletteModal.svelte

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@
5959
}
6060
}
6161
};
62+
63+
const groupedCommands = $derived(
64+
commandPaletteManager.results.reduce(
65+
(acc, { provider: { name = 'unnamed' }, items }) => {
66+
if (acc[name]) {
67+
acc[name].push(...items);
68+
} else {
69+
acc[name] = items;
70+
}
71+
return acc;
72+
},
73+
{} as Record<string, Array<ActionItem & { id: string }>>,
74+
),
75+
);
6276
</script>
6377

6478
<svelte:window
@@ -97,13 +111,13 @@
97111
<Text>{t('command_palette_prompt_default', translations)}</Text>
98112
{/if}
99113

100-
{#each commandPaletteManager.results as result, groupIndex (result.provider.name ?? groupIndex)}
101-
{#if result.provider.name}
102-
<Heading size="tiny" class="pt-2">{result.provider.name}</Heading>
114+
{#each Object.entries(groupedCommands) as [name, items] (name)}
115+
{#if name !== 'unnamed'}
116+
<Heading size="tiny" class="pt-2">{name}</Heading>
103117
{/if}
104118
{#if commandPaletteManager.results.length > 0}
105119
<div class="flex flex-col">
106-
{#each result.items as item (item.id)}
120+
{#each items as item (item.id)}
107121
<CommandPaletteItem
108122
{item}
109123
selected={commandPaletteManager.isSelected(item)}

0 commit comments

Comments
 (0)