@devries-cameron20 / t3code Mirror · read-only / commits / f554094977
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, 01:45 UTC

fix(web): preserve unsaved keybinding edits when saving another binding (#11109)

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

Ilkka Lappeteläinen committed Oct 19, 2026 at 21:09 UTC f55409497774f4129bc7a1fc24dbd607512576ae
2 files changed +54 -6
apps/web/src/components/settings/KeybindingsSettings.logic.test.ts
+46 -1
@@ -1,6 +1,9 @@
1 import { describe, expect, it } from "vite-plus/test";
2 import type { ResolvedKeybindingsConfig } from "@t3tools/contracts";
3 -import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings";
3 +import {
4 + compileResolvedKeybindingsConfig,
5 + DEFAULT_RESOLVED_KEYBINDINGS,
6 +} from "@t3tools/shared/keybindings";
7
8 import {
9 buildKeybindingRows,
@@ -115,6 +118,48 @@ describe("KeybindingsSettings.logic", () => {
118 }
119 });
120
121 + it("keeps sibling row identities when a saved binding moves to the end", () => {
122 + const bindings = compileResolvedKeybindingsConfig([
123 + { command: "chat.new", key: "mod+n" },
124 + { command: "terminal.toggle", key: "mod+j" },
125 + { command: "terminal.toggle", key: "mod+k", when: "terminalFocus" },
126 + ]);
127 + const before = buildKeybindingRows(bindings);
128 + const after = buildKeybindingRows([
129 + ...bindings.slice(1),
130 + ...compileResolvedKeybindingsConfig([{ command: "chat.new", key: "mod+shift+n" }]),
131 + ]);
132 +
133 + expect(after.filter((row) => row.command === "terminal.toggle").map((row) => row.id)).toEqual(
134 + before.filter((row) => row.command === "terminal.toggle").map((row) => row.id),
135 + );
136 + expect(after.find((row) => row.command === "chat.new")?.id).not.toBe(
137 + before.find((row) => row.command === "chat.new")?.id,
138 + );
139 + });
140 +
141 + it("shares a stable editor for resolved duplicates but separates commands, shortcuts, and conditions", () => {
142 + const bindings = compileResolvedKeybindingsConfig([
143 + { command: "terminal.toggle", key: "mod+esc", when: "terminalFocus" },
144 + { command: "terminal.toggle", key: "mod+escape", when: "(terminalFocus)" },
145 + { command: "terminal.toggle", key: "mod+esc", when: "!terminalFocus" },
146 + { command: "terminal.toggle", key: "mod+j", when: "terminalFocus" },
147 + { command: "chat.new", key: "mod+esc", when: "terminalFocus" },
148 + ]);
149 + const rows = buildKeybindingRows(bindings);
150 + expect(rows.map(({ command, key, when }) => ({ command, key, when }))).toEqual([
151 + { command: "chat.new", key: "mod+esc", when: "terminalFocus" },
152 + { command: "terminal.toggle", key: "mod+esc", when: "terminalFocus" },
153 + { command: "terminal.toggle", key: "mod+esc", when: "!terminalFocus" },
154 + { command: "terminal.toggle", key: "mod+j", when: "terminalFocus" },
155 + ]);
156 + expect(new Set(rows.map((row) => row.id)).size).toBe(4);
157 + expect(rows.find((row) => row.command === "chat.new")?.conflicts).toEqual(["Terminal: Toggle"]);
158 + expect(buildKeybindingRows(bindings.slice(1)).map((row) => row.id)).toEqual(
159 + rows.map((row) => row.id),
160 + );
161 + });
162 +
163 it("builds searchable rows with readable key and when values", () => {
164 const rows = filterKeybindingRows(
165 buildKeybindingRows([
apps/web/src/components/settings/KeybindingsSettings.logic.ts
+8 -5
@@ -244,12 +244,14 @@ export function groupKeybindingRows(
244 export function buildKeybindingRows(
245 keybindings: ResolvedKeybindingsConfig,
246 ): ReadonlyArray<KeybindingRow> {
247 - const rows = keybindings.map((binding, index) => {
247 + const rowsById = new Map<string, KeybindingRow>();
248 + for (const binding of keybindings) {
249 const defaultBinding = defaultBindingForBinding(binding);
250 const key = shortcutToKeybindingInput(binding.shortcut);
251 const when = whenAstToExpression(binding.whenAst);
251 - return {
252 - id: `${keybindingRowId(binding.command, key, when)}\u0000${index}`,
252 + const id = keybindingRowId(binding.command, key, when);
253 + rowsById.set(id, {
254 + id,
255 command: binding.command,
256 key,
257 when,
@@ -258,8 +260,9 @@ export function buildKeybindingRows(
260 defaultWhen: whenAstToExpression(defaultBinding?.whenAst),
261 binding,
262 conflicts: [],
261 - } satisfies KeybindingRow;
262 - });
263 + });
264 + }
265 + const rows = [...rowsById.values()];
266
267 const rowsWithConflicts = rows.map((row) => {
268 const conflicts = keybindingConflictLabels(rows, {