@devries-cameron20 / t3code Mirror · read-only / commits / 734e887671
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 23, 05:30 UTC

perf(web): searching keybindings only renders rows entering or leaving the filter (#20840)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 17, 2026 at 02:02 UTC 734e8876713b0238deb8339ac92982c5bedb02ca
3 files changed +114 -92
apps/web/src/components/settings/KeybindingsSettings.logic.test.ts
+86 -77
@@ -7,6 +7,7 @@ import {
7 buildKeybindingCommandOptions,
8 buildWhenVariableOptions,
9 commandLabel,
10 + filterKeybindingRows,
11 groupKeybindingRows,
12 keybindingConflictLabels,
13 keybindingFromKeyboardEvent,
@@ -19,7 +20,7 @@ import {
20
21 describe("KeybindingsSettings.logic", () => {
22 it("lists composer, provider, and pull request commands with editable defaults", () => {
22 - const rows = buildKeybindingRows(DEFAULT_RESOLVED_KEYBINDINGS, "");
23 + const rows = buildKeybindingRows(DEFAULT_RESOLVED_KEYBINDINGS);
24 for (const command of [
25 "composer.sendAlternate",
26 "composer.sendBackground",
@@ -43,24 +44,34 @@ describe("KeybindingsSettings.logic", () => {
44 }
45 });
46 it("finds the editable shortcut for sending the first queued message", () => {
46 - expect(buildKeybindingRows(DEFAULT_RESOLVED_KEYBINDINGS, "first queued")).toContainEqual(
47 + expect(
48 + filterKeybindingRows(buildKeybindingRows(DEFAULT_RESOLVED_KEYBINDINGS), "first queued"),
49 + ).toContainEqual(
50 expect.objectContaining({
51 command: "thread.steerQueuedMessage",
52 key: "mod+shift+enter",
53 }),
54 );
55 });
56 + it("filtering keeps the row objects so unchanged rows skip rendering", () => {
57 + const rows = buildKeybindingRows(DEFAULT_RESOLVED_KEYBINDINGS);
58 + const filtered = filterKeybindingRows(rows, "terminal");
59 + expect(filtered.length).toBeGreaterThan(0);
60 + expect(filtered.length).toBeLessThan(rows.length);
61 + for (const row of filtered) expect(rows).toContain(row);
62 + expect(filterKeybindingRows(rows, " ")).toBe(rows);
63 + });
64 it.each(["pu", "pull request", "copy link", "thread id"])(
65 "finds the copy link shortcut with %s",
66 (query) => {
56 - const rows = buildKeybindingRows(DEFAULT_RESOLVED_KEYBINDINGS, query);
67 + const rows = filterKeybindingRows(buildKeybindingRows(DEFAULT_RESOLVED_KEYBINDINGS), query);
68 expect(rows).toContainEqual(
69 expect.objectContaining({ command: "thread.copyReference", key: "mod+shift+c" }),
70 );
71 },
72 );
73 it("groups rows by command area in page order and drops empty groups", () => {
63 - const groups = groupKeybindingRows(buildKeybindingRows(DEFAULT_RESOLVED_KEYBINDINGS, ""));
74 + const groups = groupKeybindingRows(buildKeybindingRows(DEFAULT_RESOLVED_KEYBINDINGS));
75 expect(groups.map((group) => group.title)).toEqual([
76 "Navigation",
77 "Threads",
@@ -74,9 +85,11 @@ describe("KeybindingsSettings.logic", () => {
85 expect(composer?.rows.map((row) => row.command)).toEqual(
86 expect.arrayContaining(["composer.host", "modelPicker.toggle"]),
87 );
77 - expect(groupKeybindingRows(buildKeybindingRows(DEFAULT_RESOLVED_KEYBINDINGS, "split"))).toEqual(
78 - [expect.objectContaining({ id: "terminal" })],
79 - );
88 + expect(
89 + groupKeybindingRows(
90 + filterKeybindingRows(buildKeybindingRows(DEFAULT_RESOLVED_KEYBINDINGS), "split"),
91 + ),
92 + ).toEqual([expect.objectContaining({ id: "terminal" })]);
93 });
94 it("orders Usage bindings and command choices like the page", () => {
95 const expected = [
@@ -93,7 +106,9 @@ describe("KeybindingsSettings.logic", () => {
106 DEFAULT_RESOLVED_KEYBINDINGS,
107 DEFAULT_RESOLVED_KEYBINDINGS.toReversed(),
108 ]) {
96 - expect(buildKeybindingRows(bindings, "usage").map((row) => row.command)).toEqual(expected);
109 + expect(
110 + filterKeybindingRows(buildKeybindingRows(bindings), "usage").map((row) => row.command),
111 + ).toEqual(expected);
112 expect(
113 buildKeybindingCommandOptions(bindings).filter((command) => command.startsWith("usage.")),
114 ).toEqual(expected);
@@ -101,8 +116,8 @@ describe("KeybindingsSettings.logic", () => {
116 });
117
118 it("builds searchable rows with readable key and when values", () => {
104 - const rows = buildKeybindingRows(
105 - [
119 + const rows = filterKeybindingRows(
120 + buildKeybindingRows([
121 {
122 command: "terminal.toggle",
123 shortcut: {
@@ -118,7 +133,7 @@ describe("KeybindingsSettings.logic", () => {
133 node: { type: "identifier", name: "terminalFocus" },
134 },
135 },
121 - ] satisfies ResolvedKeybindingsConfig,
136 + ] satisfies ResolvedKeybindingsConfig),
137 "terminal",
138 );
139
@@ -345,81 +360,75 @@ describe("KeybindingsSettings.logic", () => {
360 });
361
362 it("marks each default shortcut for multi-binding commands as default", () => {
348 - const rows = buildKeybindingRows(
349 - [
350 - {
351 - command: "chat.new",
352 - shortcut: {
353 - key: "n",
354 - modKey: true,
355 - metaKey: false,
356 - ctrlKey: false,
357 - altKey: false,
358 - shiftKey: false,
359 - },
360 - whenAst: {
361 - type: "not",
362 - node: { type: "identifier", name: "terminalFocus" },
363 - },
363 + const rows = buildKeybindingRows([
364 + {
365 + command: "chat.new",
366 + shortcut: {
367 + key: "n",
368 + modKey: true,
369 + metaKey: false,
370 + ctrlKey: false,
371 + altKey: false,
372 + shiftKey: false,
373 },
365 - {
366 - command: "chat.new",
367 - shortcut: {
368 - key: "o",
369 - modKey: true,
370 - metaKey: false,
371 - ctrlKey: false,
372 - altKey: false,
373 - shiftKey: true,
374 - },
375 - whenAst: {
376 - type: "not",
377 - node: { type: "identifier", name: "terminalFocus" },
378 - },
374 + whenAst: {
375 + type: "not",
376 + node: { type: "identifier", name: "terminalFocus" },
377 },
380 - ] satisfies ResolvedKeybindingsConfig,
381 - "",
382 - );
378 + },
379 + {
380 + command: "chat.new",
381 + shortcut: {
382 + key: "o",
383 + modKey: true,
384 + metaKey: false,
385 + ctrlKey: false,
386 + altKey: false,
387 + shiftKey: true,
388 + },
389 + whenAst: {
390 + type: "not",
391 + node: { type: "identifier", name: "terminalFocus" },
392 + },
393 + },
394 + ] satisfies ResolvedKeybindingsConfig);
395
396 expect(rows.map((row) => row.source)).toEqual(["Default", "Default"]);
397 });
398
399 it("reports conflicting shortcuts that share an active when context", () => {
388 - const rows = buildKeybindingRows(
389 - [
390 - {
391 - command: "chat.new",
392 - shortcut: {
393 - key: "n",
394 - modKey: true,
395 - metaKey: false,
396 - ctrlKey: false,
397 - altKey: false,
398 - shiftKey: false,
399 - },
400 - whenAst: {
401 - type: "not",
402 - node: { type: "identifier", name: "terminalFocus" },
403 - },
400 + const rows = buildKeybindingRows([
401 + {
402 + command: "chat.new",
403 + shortcut: {
404 + key: "n",
405 + modKey: true,
406 + metaKey: false,
407 + ctrlKey: false,
408 + altKey: false,
409 + shiftKey: false,
410 },
405 - {
406 - command: "chat.newLocal",
407 - shortcut: {
408 - key: "n",
409 - modKey: true,
410 - metaKey: false,
411 - ctrlKey: false,
412 - altKey: false,
413 - shiftKey: false,
414 - },
415 - whenAst: {
416 - type: "not",
417 - node: { type: "identifier", name: "terminalFocus" },
418 - },
411 + whenAst: {
412 + type: "not",
413 + node: { type: "identifier", name: "terminalFocus" },
414 },
420 - ] satisfies ResolvedKeybindingsConfig,
421 - "",
422 - );
415 + },
416 + {
417 + command: "chat.newLocal",
418 + shortcut: {
419 + key: "n",
420 + modKey: true,
421 + metaKey: false,
422 + ctrlKey: false,
423 + altKey: false,
424 + shiftKey: false,
425 + },
426 + whenAst: {
427 + type: "not",
428 + node: { type: "identifier", name: "terminalFocus" },
429 + },
430 + },
431 + ] satisfies ResolvedKeybindingsConfig);
432
433 expect(rows[0]?.conflicts).toEqual(["Chat: New Local"]);
434 expect(
apps/web/src/components/settings/KeybindingsSettings.logic.ts
+11 -6
@@ -243,9 +243,7 @@ export function groupKeybindingRows(
243
244 export function buildKeybindingRows(
245 keybindings: ResolvedKeybindingsConfig,
246 - query: string,
246 ): ReadonlyArray<KeybindingRow> {
248 - const normalizedQuery = query.trim().toLowerCase();
247 const rows = keybindings.map((binding, index) => {
248 const defaultBinding = defaultBindingForBinding(binding);
249 const key = shortcutToKeybindingInput(binding.shortcut);
@@ -280,11 +278,18 @@ export function buildKeybindingRows(
278 return left.key.localeCompare(right.key);
279 });
280
283 - if (normalizedQuery.length === 0) {
284 - return rowsWithConflicts;
285 - }
281 + return rowsWithConflicts;
282 +}
283
287 - return rowsWithConflicts.filter((row) => {
284 +// Filtering keeps the row objects so rows that stay visible while the query
285 +// changes receive the same props and skip rendering.
286 +export function filterKeybindingRows(
287 + rows: ReadonlyArray<KeybindingRow>,
288 + query: string,
289 +): ReadonlyArray<KeybindingRow> {
290 + const normalizedQuery = query.trim().toLowerCase();
291 + if (normalizedQuery.length === 0) return rows;
292 + return rows.filter((row) => {
293 return (
294 row.command.toLowerCase().includes(normalizedQuery) ||
295 commandLabel(row.command).toLowerCase().includes(normalizedQuery) ||
apps/web/src/components/settings/KeybindingsSettings.tsx
+17 -9
@@ -52,6 +52,7 @@ import { Toggle } from "../ui/toggle";
52 import { toastManager } from "../ui/toast";
53 import {
54 buildKeybindingRows,
55 + filterKeybindingRows,
56 buildKeybindingCommandOptions,
57 buildWhenVariableOptions,
58 commandLabel,
@@ -1271,6 +1272,18 @@ function keybindingAnchorIds(rows: ReturnType<typeof buildKeybindingRows>) {
1272 return ids;
1273 }
1274
1275 +// Rows come from a hook so they are cached on the server keybindings alone. Built
1276 +// inline, the compiler joins them to the query's cache scope (filtering might
1277 +// mutate them), and every keystroke rebuilds and re-renders every row.
1278 +function useKeybindingCatalog() {
1279 + const serverKeybindings = useSettingsScope().environment?.serverConfig?.keybindings;
1280 + const merged = mergeWithDefaultKeybindings(serverKeybindings ?? []);
1281 + return {
1282 + commandOptions: buildKeybindingCommandOptions(merged),
1283 + allRows: buildKeybindingRows(merged),
1284 + };
1285 +}
1286 +
1287 export function KeybindingsSettingsPanel() {
1288 const { environment: primaryEnvironment, connectedEnvironments } = useSettingsScope();
1289 const canOpenKeybindingsFile = useEnvironmentScope(
@@ -1305,13 +1318,8 @@ export function KeybindingsSettingsPanel() {
1318 if (searchTargetId.startsWith("keybinding-")) setQuery("");
1319 }
1320 const whenVariables = buildWhenVariableOptions();
1308 - const serverKeybindings = primaryEnvironment?.serverConfig?.keybindings;
1309 - // Each derivation merges the defaults itself so the command options key on the
1310 - // server keybindings alone and do not rebuild on every search keystroke.
1311 - const commandOptions = buildKeybindingCommandOptions(
1312 - mergeWithDefaultKeybindings(serverKeybindings ?? []),
1313 - );
1314 - const rows = buildKeybindingRows(mergeWithDefaultKeybindings(serverKeybindings ?? []), query);
1321 + const { commandOptions, allRows } = useKeybindingCatalog();
1322 + const rows = filterKeybindingRows(allRows, query);
1323 const groups = groupKeybindingRows(rows);
1324 const anchorIds = keybindingAnchorIds(rows);
1325
@@ -1423,7 +1431,7 @@ export function KeybindingsSettingsPanel() {
1431 const cancelAdd = () => setIsAddingBinding(false);
1432
1433 const rowActions: KeybindingRowActions = {
1426 - allRows: rows,
1434 + allRows,
1435 variables: whenVariables,
1436 onSave: saveKeybinding,
1437 onReset: resetKeybinding,
@@ -1479,7 +1487,7 @@ export function KeybindingsSettingsPanel() {
1487 <SettingsGroup>
1488 <NewKeybindingSettingsRow
1489 commandOptions={commandOptions}
1482 - allRows={rows}
1490 + allRows={allRows}
1491 variables={whenVariables}
1492 isSaving={savingCommand !== null}
1493 onSave={saveKeybinding}