Skip to content

Commit d334917

Browse files
committed
fix(web): rank keybinding results last in the command palette too
1 parent 96da3a8 commit d334917

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
filterPinnedBrowseEntries,
1212
filterCommandPaletteGroups,
1313
reduceCommandPaletteUiState,
14+
type CommandPaletteActionItem,
1415
type CommandPaletteGroup,
1516
} from "./CommandPalette.logic";
1617

@@ -738,3 +739,33 @@ it.each([
738739
"Implementation",
739740
]);
740741
});
742+
743+
describe("filterCommandPaletteGroups", () => {
744+
it("sorts secondary settings results after other matches", () => {
745+
const item = (value: string, title: string, secondary?: boolean) =>
746+
({
747+
kind: "action",
748+
value,
749+
title,
750+
searchTerms: [title, "General"],
751+
icon: null,
752+
run: async () => undefined,
753+
...(secondary ? { secondary } : {}),
754+
}) satisfies CommandPaletteActionItem;
755+
const [group] = filterCommandPaletteGroups({
756+
activeGroups: [],
757+
query: "model",
758+
isInSubmenu: false,
759+
projectSearchItems: [],
760+
settingsSearchItems: [
761+
item("setting:keybinding-modelPicker.toggle", "Model Picker: Toggle", true),
762+
item("setting:default-model", "Default model"),
763+
],
764+
threadSearchItems: [],
765+
});
766+
expect(group?.items.map((entry) => entry.value)).toEqual([
767+
"setting:default-model",
768+
"setting:keybinding-modelPicker.toggle",
769+
]);
770+
});
771+
});

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ export interface CommandPaletteItem {
142142
/** Optional content rendered inline after the title text (before the timestamp). */
143143
readonly titleTrailingContent?: ReactNode;
144144
readonly shortcutCommand?: KeybindingCommand;
145+
/** Sorts after every other match in its group; see `SettingsSearchItem.secondary`. */
146+
readonly secondary?: boolean;
145147
}
146148

147149
export interface CommandPaletteActionItem extends CommandPaletteItem {
@@ -434,7 +436,12 @@ export function filterCommandPaletteGroups(input: {
434436
rank: rankCommandPaletteItemMatch(item, normalizedQuery, queryTokens),
435437
});
436438
})
437-
.toSorted((left, right) => right.rank - left.rank || left.index - right.index)
439+
.toSorted(
440+
(left, right) =>
441+
Number(left.item.secondary ?? false) - Number(right.item.secondary ?? false) ||
442+
right.rank - left.rank ||
443+
left.index - right.index,
444+
)
438445
.map((entry) => entry.item);
439446

440447
if (items.length === 0) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,6 +2058,7 @@ function OpenCommandPaletteDialog(props: {
20582058
searchTerms: [item.title, SETTINGS_SECTION_LABELS[item.to], ...(item.searchTerms ?? [])],
20592059
title: item.title,
20602060
description: `Settings · ${SETTINGS_SECTION_LABELS[item.to]}`,
2061+
...(item.secondary ? { secondary: true } : {}),
20612062
icon: <SettingsIcon className={ITEM_ICON_CLASS} />,
20622063
run: async () => {
20632064
await navigate({

0 commit comments

Comments
 (0)