Skip to content

Commit 5864678

Browse files
committed
fix(web): palette suggestions skip duplicates and submenu-only queries
1 parent bbd15ec commit 5864678

3 files changed

Lines changed: 21 additions & 8 deletions

File tree

‎apps/web/src/components/CommandPalette.logic.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,15 @@ describe("buildThreadActionItems", () => {
190190
};
191191
const addProject = action("action:add-project", "Add project");
192192
const rootGroups = [{ value: "actions", label: "Actions", items: [newThreadIn, addProject] }];
193-
const allOptions = {
194-
rootGroups,
195-
nestedItems: buildNestedSearchItems([newThreadIn, addProject]),
196-
};
197193
const search = (query: string, isInSubmenu: boolean) =>
198194
filterCommandPaletteGroups({
199195
activeGroups: isInSubmenu ? newThreadIn.groups : rootGroups,
200196
query,
201197
isInSubmenu,
202-
allOptions,
198+
allOptions: {
199+
rootGroups,
200+
nestedItems: buildNestedSearchItems([newThreadIn, addProject], query),
201+
},
203202
projectSearchItems: [],
204203
threadSearchItems: [
205204
...buildThreadActionItems({
@@ -215,6 +214,7 @@ describe("buildThreadActionItems", () => {
215214
"Suggestions",
216215
["New thread in t3code"],
217216
]);
217+
expect(search("new thread", false).map(([label]) => label)).not.toContain("Suggestions");
218218
expect(search("t3", true)).toEqual([["Projects", ["t3code"]]]);
219219
expect(search("add project", true)).toEqual([["Actions", ["Add project"]]]);
220220
});

‎apps/web/src/components/CommandPalette.logic.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,17 +626,25 @@ export function filterCommandPaletteGroups(input: {
626626
/** Every option inside a submenu as one row, e.g. "New thread in t3code" or "Change theme: Dracula". */
627627
export function buildNestedSearchItems(
628628
items: ReadonlyArray<CommandPaletteActionItem | CommandPaletteSubmenuItem>,
629+
query: string,
629630
): CommandPaletteActionItem[] {
631+
const nameOf = (item: CommandPaletteItem) =>
632+
typeof item.title === "string" ? item.title : item.searchTitle;
633+
const topLevelNames = new Set(items.map(nameOf));
634+
const foldedQuery = foldSearchQuery(query);
630635
return items.flatMap((parent) => {
631636
if (parent.kind !== "submenu" || typeof parent.title !== "string") return [];
632637
const stem = parent.title.replace(/(\.\.\.|…)$/u, "");
638+
// A query that only names the submenu ("new thread in") wants the submenu row itself.
639+
if (foldSearchQuery(stem).startsWith(foldedQuery)) return [];
633640
const prefix = stem === parent.title ? `${stem}: ` : `${stem.trimEnd()} `;
634641
return parent.groups.flatMap((group) =>
635642
group.items.flatMap((child) => {
636-
const name = typeof child.title === "string" ? child.title : child.searchTitle;
643+
const name = nameOf(child);
637644
if (child.kind !== "action" || name === undefined) return [];
638-
const { searchTitle: _searchTitle, ...rest } = child;
639645
const title = `${prefix}${name}`;
646+
if (topLevelNames.has(title)) return [];
647+
const { searchTitle: _searchTitle, ...rest } = child;
640648
// Only the combined title: child keywords like "theme" would list every theme.
641649
return [{ ...rest, title, searchTerms: [title] }];
642650
}),

‎apps/web/src/components/CommandPalette.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,12 @@ function OpenCommandPaletteDialog(props: {
16831683
query: deferredQuery,
16841684
isInSubmenu: currentView !== null,
16851685
...(deferredQuery.trim().length > 0
1686-
? { allOptions: { rootGroups, nestedItems: buildNestedSearchItems(actionItems) } }
1686+
? {
1687+
allOptions: {
1688+
rootGroups,
1689+
nestedItems: buildNestedSearchItems(actionItems, deferredQuery),
1690+
},
1691+
}
16871692
: {}),
16881693
projectSearchItems: projectSearchItems,
16891694
settingsSearchItems,

0 commit comments

Comments
 (0)