The best way to control Claude Code, Codex and more from any computer or phone
fix(web): keep action shortcuts when editing other fields (#18412)
Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Alex Southwell committed
Oct 20, 2026 at 08:15 UTC
7cca7d17efefcc8be7901a947f0b10b68892c2c1
2 files changed
+95
-20
apps/web/src/components/settings/useProjectScriptSettings.browser.test.tsx
+92
-20
@@ -66,52 +66,65 @@ const lintBinding: ResolvedKeybindingsConfig = [
66
},
67
},
68
];
69
-const input = (keybinding: string | null): NewProjectScriptInput => ({
69
+const input: NewProjectScriptInput = {
70
name: lint.name,
71
command: lint.command,
72
icon: lint.icon,
73
runOnWorktreeCreate: false,
74
waitForSetup: false,
75
runOnSettle: false,
76
- keybinding,
76
previewUrl: null,
77
autoOpenPreview: false,
79
-});
78
+};
79
80
type ProjectScriptSettings = ReturnType<typeof useProjectScriptSettings>;
81
82
function Probe(props: {
84
- keybindings: ResolvedKeybindingsConfig;
83
+ targets: Parameters<typeof useProjectScriptSettings>[0];
84
onResult: (settings: ProjectScriptSettings) => void;
85
}) {
87
- props.onResult(
88
- useProjectScriptSettings([
89
- {
90
- environmentId,
91
- settings: DEFAULT_SERVER_SETTINGS,
92
- keybindings: props.keybindings,
93
- project: { id: ProjectId.make("project"), scripts: [lint] },
94
- },
95
- ]),
96
- );
86
+ props.onResult(useProjectScriptSettings(props.targets));
87
return null;
88
}
89
90
let root: Root;
91
let container: HTMLDivElement;
92
103
-async function renderSettings(keybindings: ResolvedKeybindingsConfig) {
93
+async function renderSettings(
94
+ keybindings: ResolvedKeybindingsConfig,
95
+ scope: "project" | "environment" = "project",
96
+) {
97
let settings: ProjectScriptSettings | undefined;
98
await act(async () =>
106
- root.render(<Probe keybindings={keybindings} onResult={(next) => (settings = next)} />),
99
+ root.render(
100
+ <Probe
101
+ targets={[
102
+ {
103
+ environmentId,
104
+ settings: {
105
+ ...DEFAULT_SERVER_SETTINGS,
106
+ defaultProjectScripts: scope === "environment" ? [lint] : [],
107
+ },
108
+ keybindings,
109
+ ...(scope === "project"
110
+ ? { project: { id: ProjectId.make("project"), scripts: [lint] } }
111
+ : {}),
112
+ },
113
+ ]}
114
+ onResult={(next) => (settings = next)}
115
+ />,
116
+ ),
117
);
118
return settings!;
119
}
120
111
-async function submitInAct(submit: ProjectScriptSettings["submit"], keybinding: string | null) {
121
+async function submitInAct(
122
+ submit: ProjectScriptSettings["submit"],
123
+ changes: Partial<NewProjectScriptInput>,
124
+) {
125
let result: Awaited<ReturnType<typeof submit>> | undefined;
126
await act(async () => {
114
- result = await submit(lint.id, input(keybinding));
127
+ result = await submit(lint.id, { ...input, ...changes });
128
});
129
return result!;
130
}
@@ -134,10 +147,34 @@ afterEach(async () => {
147
});
148
149
describe("useProjectScriptSettings", () => {
150
+ it.each(["project", "environment"] as const)(
151
+ "preserves the shortcut for %s action name and command edits",
152
+ async (scope) => {
153
+ const { submit } = await renderSettings(lintBinding, scope);
154
+ const changes = { name: "Lint and fix", command: "vp lint --fix" };
155
+
156
+ const result = await submitInAct(submit, changes);
157
+
158
+ expect(result._tag).toBe("Success");
159
+ const scripts = [expect.objectContaining({ id: lint.id, ...changes })];
160
+ expect(commands.updateSettings).toHaveBeenCalledExactlyOnceWith({
161
+ environmentId,
162
+ input: {
163
+ patch:
164
+ scope === "project"
165
+ ? { projectSettingsOverrides: { project: { defaultProjectScripts: scripts } } }
166
+ : { defaultProjectScripts: scripts },
167
+ },
168
+ });
169
+ expect(commands.removeKeybinding).not.toHaveBeenCalled();
170
+ expect(commands.upsertKeybinding).not.toHaveBeenCalled();
171
+ },
172
+ );
173
+
174
it("saves a recorded action shortcut", async () => {
175
const { submit } = await renderSettings([]);
176
140
- const result = await submitInAct(submit, "mod+shift+k");
177
+ const result = await submitInAct(submit, { keybinding: "mod+shift+k" });
178
179
expect(result._tag).toBe("Success");
180
expect(commands.upsertKeybinding).toHaveBeenCalledWith({
@@ -149,7 +186,7 @@ describe("useProjectScriptSettings", () => {
186
it("removes a cleared action shortcut", async () => {
187
const { submit } = await renderSettings(lintBinding);
188
152
- const result = await submitInAct(submit, null);
189
+ const result = await submitInAct(submit, { keybinding: null });
190
191
expect(result._tag).toBe("Success");
192
expect(commands.removeKeybinding).toHaveBeenCalledWith({
@@ -158,4 +195,39 @@ describe("useProjectScriptSettings", () => {
195
});
196
expect(commands.upsertKeybinding).not.toHaveBeenCalled();
197
});
198
+
199
+ it("replaces an explicitly changed action shortcut", async () => {
200
+ const { submit } = await renderSettings(lintBinding);
201
+
202
+ const result = await submitInAct(submit, { keybinding: "mod+shift+l" });
203
+
204
+ expect(result._tag).toBe("Success");
205
+ expect(commands.upsertKeybinding).toHaveBeenCalledExactlyOnceWith({
206
+ environmentId,
207
+ input: {
208
+ command: "script.lint.run",
209
+ key: "mod+shift+l",
210
+ replace: { command: "script.lint.run", key: "mod+shift+k" },
211
+ },
212
+ });
213
+ expect(commands.removeKeybinding).not.toHaveBeenCalled();
214
+ });
215
+
216
+ it("removes the shortcut when its action is deleted", async () => {
217
+ const { persist } = await renderSettings(lintBinding);
218
+
219
+ await act(async () => {
220
+ expect((await persist(() => []))._tag).toBe("Success");
221
+ });
222
+
223
+ expect(commands.updateSettings).toHaveBeenCalledExactlyOnceWith({
224
+ environmentId,
225
+ input: { patch: { projectSettingsOverrides: { project: { defaultProjectScripts: [] } } } },
226
+ });
227
+ expect(commands.removeKeybinding).toHaveBeenCalledExactlyOnceWith({
228
+ environmentId,
229
+ input: { key: "mod+shift+k", command: "script.lint.run" },
230
+ });
231
+ expect(commands.upsertKeybinding).not.toHaveBeenCalled();
232
+ });
233
});
apps/web/src/components/settings/useProjectScriptSettings.ts
+3
@@ -140,6 +140,9 @@ export function useProjectScriptSettings(
140
.filter((script) => !effectiveScripts.some((next) => next.id === script.id))
141
.map((script) => script.id);
142
for (const id of changedIds) {
143
+ if (keybinding === undefined && effectiveScripts.some((script) => script.id === id)) {
144
+ continue;
145
+ }
146
const command = commandForProjectScript(id);
147
const previousValue = keybindingValueForCommand(keybindings, command);
148
const previous = previousValue