@devries-cameron20 / t3code Mirror · read-only / commits / 3d31ffcd9a
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

feat(web): search actions when adding keybindings (#28612)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Lukas Böhm committed Nov 21, 2026 at 03:17 UTC 3d31ffcd9a4489a62840a0c21d07d273aab31775
5 files changed +204 -19
apps/web/src/components/settings/KeybindingsSettings.browser.test.tsx
+31
@@ -196,3 +196,34 @@ it("re-enables Save when a When editor closes on an expression it could not pars
196 await expect.element(expression).toHaveValue("terminalFocus");
197 await expect.element(screen.getByRole("button", { name: "Save" })).toBeEnabled();
198 });
199 +
200 +it("filters actions and allows additional shortcuts for assigned commands", async () => {
201 + await using screen = await render(<KeybindingsSettingsPanel />);
202 + await screen.getByRole("button", { name: "Add keybinding" }).click();
203 + const dialog = page.getByRole("dialog", { name: "Command", exact: true });
204 + const search = dialog.getByRole("combobox", { name: "Search", exact: true });
205 + await expect.element(search).toHaveFocus();
206 + await userEvent.keyboard("sidebar.toggle");
207 + const assigned = page.getByRole("option", { name: /Sidebar: Toggle/ });
208 + await expect.element(assigned).not.toHaveAttribute("aria-disabled", "true");
209 + await expect.element(assigned.element().querySelector("kbd")!).toBeVisible();
210 + await vi.waitFor(() => expect(page.getByRole("option").elements()).toHaveLength(1));
211 + await assigned.click();
212 + const command = screen.getByRole("combobox", { name: "Command", exact: true });
213 + await expect.element(command).toHaveTextContent("Sidebar: Toggle");
214 + await command.click();
215 + await search.fill("Opposite Queue");
216 + await expect
217 + .element(page.getByRole("option", { name: /Composer: Opposite Queue or Steer Action/ }))
218 + .toBeVisible();
219 + await vi.waitFor(() => expect(page.getByRole("option").elements()).toHaveLength(1));
220 + await search.fill("no-such-action");
221 + await expect.element(page.getByText("No results found.")).toBeVisible();
222 + await search.fill("composer.cycleHost");
223 + const available = page.getByRole("option", { name: "Composer: Cycle Host" });
224 + await expect.element(available).not.toHaveAttribute("aria-disabled", "true");
225 + await available.click();
226 + await expect
227 + .element(screen.getByRole("combobox", { name: "Command", exact: true }))
228 + .toHaveTextContent("Composer: Cycle Host");
229 +});
apps/web/src/components/settings/KeybindingsSettings.logic.test.ts
+57
@@ -61,6 +61,62 @@ describe("KeybindingsSettings.logic", () => {
61 );
62 });
63
64 + it("marks only bindings shadowed by later unconditional or matching conditions", () => {
65 + const bindings = compileResolvedKeybindingsConfig([
66 + { command: "sidebar.toggle", key: "mod+b" },
67 + { command: "terminal.toggle", key: "meta+b", when: "true" },
68 + { command: "chat.new", key: "mod+n", when: "terminalFocus" },
69 + { command: "terminal.new", key: "mod+n", when: "(terminalFocus)" },
70 + { command: "chat.new", key: "mod+j" },
71 + { command: "terminal.toggle", key: "mod+j", when: "terminalFocus" },
72 + { command: "chat.new", key: "mod+k", when: "!terminalFocus" },
73 + { command: "terminal.toggle", key: "mod+k", when: "terminalFocus" },
74 + { command: "chat.new", key: "mod+l", when: "terminalFocus" },
75 + { command: "terminal.toggle", key: "mod+l" },
76 + ]);
77 + const rows = buildKeybindingRows(bindings, "MacIntel");
78 + expect(rows.filter((row) => row.previewLabels.length === 0).map((row) => row.binding)).toEqual([
79 + bindings[8],
80 + bindings[2],
81 + bindings[0],
82 + ]);
83 + expect(rows.filter((row) => row.previewLabels.length > 0)).toHaveLength(7);
84 + const sendBindings = compileResolvedKeybindingsConfig([
85 + { command: "composer.sendAlternate", key: "mod+enter" },
86 + { command: "chat.new", key: "mod+enter" },
87 + ]);
88 + for (const sendShortcut of ["enter", "mod-enter", "mod-enter-multiline"] as const) {
89 + expect(
90 + buildKeybindingRows(sendBindings, "MacIntel", sendShortcut).find(
91 + (row) => row.command === "composer.sendAlternate",
92 + )?.previewLabels.length === 0,
93 + ).toBe(sendShortcut === "enter");
94 + }
95 + for (const command of ["composer.sendAlternate", "composer.sendBackground"] as const) {
96 + const binding = compileResolvedKeybindingsConfig([{ command, key: "mod+enter" }]);
97 + const labels = (mode: "enter" | "mod-enter" | "mod-enter-multiline") =>
98 + buildKeybindingRows(binding, "Win32", mode)[0]?.previewLabels;
99 + expect(labels("enter")).toEqual(["Ctrl+Enter"]);
100 + expect(labels("mod-enter")).toEqual(["Ctrl+Shift+Enter"]);
101 + expect(labels("mod-enter-multiline")).toEqual(["Ctrl+Enter", "Ctrl+Shift+Enter"]);
102 + }
103 + const shiftedBindings = compileResolvedKeybindingsConfig([
104 + { command: "chat.new", key: "mod+shift+enter" },
105 + { command: "composer.sendAlternate", key: "mod+enter" },
106 + ]);
107 + for (const sendShortcut of ["enter", "mod-enter", "mod-enter-multiline"] as const) {
108 + expect(
109 + buildKeybindingRows(shiftedBindings, "MacIntel", sendShortcut).find(
110 + (row) => row.command === "chat.new",
111 + )?.previewLabels.length === 0,
112 + ).toBe(sendShortcut === "mod-enter");
113 + }
114 + expect(
115 + buildKeybindingRows(bindings, "Win32").find((row) => row.command === "sidebar.toggle")
116 + ?.previewLabels.length === 0,
117 + ).toBe(false);
118 + });
119 +
120 it("captures platform-specific mod shortcuts", () => {
121 expect(
122 keybindingFromKeyboardEvent(
@@ -268,6 +324,7 @@ describe("KeybindingsSettings.logic", () => {
324 rows[0]!.binding,
325 { ...rows[1]!.binding, whenAst: { type: "identifier", name: "false" } },
326 ]);
327 + expect(disabledRows.find((row) => row.when === "false")?.previewLabels).toEqual([]);
328 expect(disabledRows.map((row) => row.conflicts)).toEqual([[], []]);
329
330 expect(
apps/web/src/components/settings/KeybindingsSettings.logic.ts
+31 -2
@@ -1,5 +1,6 @@
1 import {
2 STATIC_KEYBINDING_COMMANDS,
3 + type ClientSettings,
4 type KeybindingCommand,
5 type KeybindingShortcut,
6 type KeybindingWhenNode,
@@ -15,7 +16,12 @@ import {
16 import { msg } from "gt-react";
17
18 import { m, type MessageResolver } from "../../i18n/messages";
18 -import { shortcutConflictKey, shortcutKeyFromEvent } from "../../keybindings";
19 +import {
20 + formatShortcutLabel,
21 + shortcutConflictKey,
22 + shortcutForContext,
23 + shortcutKeyFromEvent,
24 +} from "../../keybindings";
25 import { isMacPlatform } from "../../lib/utils";
26 import { METRIC_OPTIONS, WINDOW_OPTIONS } from "../usage/usageShortcuts";
27
@@ -55,6 +61,7 @@ export interface KeybindingRow {
61 readonly defaultWhen: string;
62 readonly binding: ResolvedKeybindingRule;
63 readonly conflicts: ReadonlyArray<string>;
64 + readonly previewLabels: ReadonlyArray<string>;
65 }
66
67 export type WhenVariableOption = string;
@@ -276,10 +283,31 @@ export function groupKeybindingRows(
283 export function buildKeybindingRows(
284 keybindings: ResolvedKeybindingsConfig,
285 platform = navigator.platform,
286 + sendShortcut: ClientSettings["sendShortcut"] = "enter",
287 resolve: MessageResolver = m,
288 ): ReadonlyArray<KeybindingRow> {
289 + // Multiline sending can use either shortcut; settings have no active composer prompt.
290 + const modifierModes =
291 + sendShortcut === "mod-enter-multiline" ? [false, true] : [sendShortcut === "mod-enter"];
292 + const previewLabels = keybindings.map(() => new Set<string>());
293 + for (const composerRequiresModifier of modifierModes) {
294 + const laterBindings = new Set<string>();
295 + for (let index = keybindings.length - 1; index >= 0; index--) {
296 + const binding = keybindings[index]!;
297 + const when = whenAstToExpression(binding.whenAst);
298 + if (when === "false") continue;
299 + const shortcut = shortcutForContext(binding, { composerRequiresModifier });
300 + const key = shortcutConflictKey(shortcut, platform);
301 + const conditionKey = `${key}:${when === "true" ? "" : when}`;
302 + // Distinct conditions may still apply in other focus contexts.
303 + if (!laterBindings.has(`${key}:`) && !laterBindings.has(conditionKey)) {
304 + previewLabels[index]!.add(formatShortcutLabel(shortcut, platform));
305 + }
306 + laterBindings.add(conditionKey);
307 + }
308 + }
309 const rowsById = new Map<string, KeybindingRow>();
282 - for (const binding of keybindings) {
310 + for (const [index, binding] of keybindings.entries()) {
311 const defaultBinding = defaultBindingForBinding(binding);
312 const key = shortcutToKeybindingInput(binding.shortcut);
313 const when = whenAstToExpression(binding.whenAst);
@@ -298,6 +326,7 @@ export function buildKeybindingRows(
326 defaultWhen: whenAstToExpression(defaultBinding?.whenAst),
327 binding,
328 conflicts: [],
329 + previewLabels: [...previewLabels[index]!],
330 });
331 }
332 const rows = [...rowsById.values()];
apps/web/src/components/settings/KeybindingsSettings.tsx
+81 -16
@@ -47,6 +47,7 @@ import { formatShortcutLabel } from "../../keybindings";
47 import { cn } from "../../lib/utils";
48 import { serverEnvironment } from "../../state/server";
49 import { useSettingsScope } from "./SettingsScopeContext";
50 +import { useClientSettings } from "../../hooks/useSettings";
51 import { Badge } from "../ui/badge";
52 import { Button } from "../ui/button";
53 import { Input } from "../ui/input";
@@ -54,7 +55,23 @@ import { InputGroup, InputGroupAddon, InputGroupInput } from "../ui/input-group"
55 import { Kbd, KbdGroup } from "../ui/kbd";
56 import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
57 import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover";
57 -import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../ui/select";
58 +import {
59 + Combobox,
60 + ComboboxTrigger,
61 + ComboboxPopup,
62 + ComboboxSearchInput,
63 + ComboboxEmpty,
64 + ComboboxList,
65 + ComboboxItem,
66 +} from "../ui/combobox";
67 +import {
68 + SelectButton,
69 + Select,
70 + SelectContent,
71 + SelectItem,
72 + SelectTrigger,
73 + SelectValue,
74 +} from "../ui/select";
75 import { Toggle } from "../ui/toggle";
76 import { toastManager } from "../ui/toast";
77 import {
@@ -1217,30 +1234,76 @@ interface NewKeybindingProps {
1234 function NewKeybindingCommandSelect({
1235 draft,
1236 commandOptions,
1237 + allRows,
1238 className,
1239 }: {
1240 draft: NewKeybindingDraft;
1241 commandOptions: ReadonlyArray<KeybindingCommandOption>;
1242 + allRows: ReadonlyArray<KeybindingRow>;
1243 className?: string | undefined;
1244 }) {
1245 const gt = useGT();
1246 const m = useMessages();
1247 + const shortcutsByCommand = new Map<
1248 + KeybindingCommand,
1249 + Array<{ id: string; label: string; when: string }>
1250 + >();
1251 + for (const row of allRows) {
1252 + for (const label of row.previewLabels) {
1253 + const shortcuts = shortcutsByCommand.get(row.command) ?? [];
1254 + shortcuts.push({ id: `${row.id}:${label}`, label, when: row.when });
1255 + shortcutsByCommand.set(row.command, shortcuts);
1256 + }
1257 + }
1258 return (
1229 - <Select
1230 - value={draft.commandDraft}
1231 - onValueChange={(value) => draft.setCommandDraft(value as KeybindingCommand)}
1259 + <Combobox
1260 + items={commandOptions}
1261 + defaultOpen
1262 + itemToStringLabel={(command) => commandLabel(command, m)}
1263 + filter={(command, query) =>
1264 + `${command} ${commandLabel(command, m)}`.toLowerCase().includes(query.trim().toLowerCase())
1265 + }
1266 + autoHighlight
1267 + value={draft.commandDraft || null}
1268 + onValueChange={(value) => value && draft.setCommandDraft(value)}
1269 >
1233 - <SelectTrigger size="sm" className={className}>
1234 - <SelectValue placeholder={gt("Command")} />
1235 - </SelectTrigger>
1236 - <SelectContent alignItemWithTrigger={false} matchTriggerWidth={false} className="max-h-72">
1237 - {commandOptions.map((command) => (
1238 - <SelectItem key={command} value={command} className="w-full">
1239 - <span className="truncate">{commandLabel(command, m)}</span>
1240 - </SelectItem>
1241 - ))}
1242 - </SelectContent>
1243 - </Select>
1270 + <ComboboxTrigger
1271 + aria-label={gt("Command")}
1272 + render={<SelectButton size="sm" />}
1273 + className={className}
1274 + >
1275 + {draft.commandDraft ? commandLabel(draft.commandDraft, m) : gt("Command")}
1276 + </ComboboxTrigger>
1277 + <ComboboxPopup aria-label={gt("Command")} className="w-96">
1278 + <ComboboxSearchInput
1279 + autoFocus
1280 + placeholder={gt("Search", { $context: "search field placeholder" })}
1281 + aria-label={gt("Search", { $context: "search field placeholder" })}
1282 + />
1283 + <ComboboxEmpty>{gt("No results found.")}</ComboboxEmpty>
1284 + <ComboboxList>
1285 + {(command: KeybindingCommandOption) => {
1286 + const shortcuts = shortcutsByCommand.get(command);
1287 + return (
1288 + <ComboboxItem key={command} value={command}>
1289 + <div className="flex min-w-0 flex-1 items-center justify-between gap-3">
1290 + <span>{commandLabel(command, m)}</span>
1291 + {shortcuts && (
1292 + <span className="flex shrink-0 flex-col items-end gap-1">
1293 + {shortcuts.map((shortcut) => (
1294 + <Kbd key={shortcut.id} title={shortcut.when || undefined}>
1295 + {shortcut.label}
1296 + </Kbd>
1297 + ))}
1298 + </span>
1299 + )}
1300 + </div>
1301 + </ComboboxItem>
1302 + );
1303 + }}
1304 + </ComboboxList>
1305 + </ComboboxPopup>
1306 + </Combobox>
1307 );
1308 }
1309
@@ -1353,6 +1416,7 @@ function NewKeybindingSettingsRow(props: NewKeybindingProps) {
1416 <NewKeybindingCommandSelect
1417 draft={draft}
1418 commandOptions={commandOptions}
1419 + allRows={allRows}
1420 className="w-56"
1421 />
1422 <KeybindingConflictWarning labels={draft.conflictLabels} />
@@ -1426,12 +1490,13 @@ function keybindingAnchorIds(rows: ReturnType<typeof buildKeybindingRows>) {
1490
1491 // Cache rows in a separate hook so the compiler does not rebuild them per search keystroke.
1492 function useKeybindingCatalog() {
1493 + const sendShortcut = useClientSettings((settings) => settings.sendShortcut);
1494 const serverKeybindings = useSettingsScope().environment?.serverConfig?.keybindings;
1495 const merged = mergeWithDefaultKeybindings(serverKeybindings ?? []);
1496 const m = useMessages();
1497 return {
1498 commandOptions: buildKeybindingCommandOptions(merged, m),
1434 - allRows: buildKeybindingRows(merged, navigator.platform, m),
1499 + allRows: buildKeybindingRows(merged, navigator.platform, sendShortcut, m),
1500 };
1501 }
1502
apps/web/src/keybindings.ts
+4 -1
@@ -110,7 +110,10 @@ export function shortcutConflictKey(
110 ].join("|");
111 }
112
113 -function shortcutForContext(binding: ResolvedKeybindingRule, context: ShortcutMatchContext) {
113 +export function shortcutForContext(
114 + binding: ResolvedKeybindingRule,
115 + context: Partial<ShortcutMatchContext>,
116 +) {
117 const shortcut = binding.shortcut;
118 // Resolve persisted Mod+Enter against send preference without rewriting saved shortcuts.
119 if (