The best way to control Claude Code, Codex and more from any computer or phone
fix(web): remember editor selections before opening folders (#19078)
Yash Singh committed
Oct 13, 2026 at 10:07 UTC
a47decf230ac0562fc5f77ea88d92efc5eb61530
4 files changed
+124
-17
apps/server/src/process/externalLauncher.test.ts
+41
@@ -1043,6 +1043,47 @@ for (const { platform, installPath, editor, args } of [
1043
);
1044
}
1045
1046
+for (const cwd of ["/workspace with spaces/", "/workspace with spaces/file.ts:12:4"]) {
1047
+ it.effect.skipIf(windowsHost)(
1048
+ `opens ${cwd} with the macOS Zed bundle when another zed is on PATH`,
1049
+ () =>
1050
+ Effect.gen(function* () {
1051
+ const fs = yield* FileSystem.FileSystem;
1052
+ const path = yield* Path.Path;
1053
+ const home = yield* fs.makeTempDirectoryScoped({ prefix: "t3-zed-collision-" });
1054
+ const executable = path.join(home, "Applications/Zed.app/Contents/MacOS/cli");
1055
+ const binDir = path.join(home, "zfs/bin");
1056
+ yield* fs.makeDirectory(path.dirname(executable), { recursive: true });
1057
+ yield* fs.makeDirectory(binDir, { recursive: true });
1058
+ for (const command of [executable, path.join(binDir, "zed")]) {
1059
+ yield* fs.writeFileString(command, "#!/bin/sh\n");
1060
+ yield* fs.chmod(command, 0o755);
1061
+ }
1062
+
1063
+ let spawned: ChildProcess.StandardCommand | undefined;
1064
+ yield* Effect.gen(function* () {
1065
+ const launcher = yield* ExternalLauncher.ExternalLauncher;
1066
+ assert.include(yield* launcher.resolveAvailableEditors(), "zed");
1067
+ yield* launcher.launchEditor({ editor: "zed", cwd });
1068
+ }).pipe(
1069
+ Effect.provide(
1070
+ layerTest({
1071
+ platform: "darwin",
1072
+ env: { HOME: home, PATH: binDir },
1073
+ onSpawn: (command) => {
1074
+ spawned = command;
1075
+ },
1076
+ }),
1077
+ ),
1078
+ );
1079
+ assert.ok(spawned);
1080
+ assert.equal(spawned.command, executable);
1081
+ assert.deepEqual(spawned.args, [cwd]);
1082
+ assert.equal(spawned.options.shell, false);
1083
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
1084
+ );
1085
+}
1086
+
1087
// JetBrains Toolbox names its bundles after the app and the installed version
1088
// (`IntelliJ IDEA 2026.1.4.app`), so the darwin branch has to list the
1089
// Applications directories the way the win32 branch does instead of probing
apps/web/src/components/chat/OpenInPicker.test.tsx
+67
-13
@@ -10,6 +10,7 @@ import type { RemoteOpenState } from "../../remoteOpen";
10
const state = vi.hoisted(() => ({
11
allowed: new Set<string>(),
12
remote: { mode: "local-exec" } as RemoteOpenState,
13
+ clientEditors: ["vscode"] as readonly EditorId[],
14
run: vi.fn(),
15
openUrl: vi.fn(),
16
setPreferred: vi.fn(),
@@ -37,15 +38,25 @@ vi.mock("../../state/session", async () => {
38
vi.mock("../../state/shell", () => ({ shellEnvironment: { openInEditor: "openInEditor" } }));
39
vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: () => state.run }));
40
vi.mock("../../state/environments", () => ({ useEnvironment: () => ({ label: "Test host" }) }));
40
-vi.mock("../../editorPreferences", () => ({
41
- usePreferredEditor: (available: readonly EditorId[]) => [
42
- available[0] ?? null,
43
- state.setPreferred,
44
- ],
45
-}));
41
+vi.mock("../../editorPreferences", async (importOriginal) => {
42
+ const actual = await importOriginal<typeof import("../../editorPreferences")>();
43
+ return {
44
+ ...actual,
45
+ usePreferredEditor: (available: readonly EditorId[]) => {
46
+ const [preferred, setPreferred] = actual.usePreferredEditor(available);
47
+ return [
48
+ preferred,
49
+ (editor: EditorId) => {
50
+ state.setPreferred(editor);
51
+ setPreferred(editor);
52
+ },
53
+ ] as const;
54
+ },
55
+ };
56
+});
57
vi.mock("../../remoteOpen", () => ({
58
useRemoteOpenState: () => state.remote,
48
- useRemoteCapableEditors: () => editors,
59
+ useRemoteCapableEditors: () => state.clientEditors,
60
useRemoteOpenHint: () => [false, state.markHintSeen],
61
openRemoteEditorUrl: state.openUrl,
62
}));
@@ -104,6 +115,7 @@ let renderer: ReactTestRenderer | undefined;
115
beforeEach(() => {
116
state.allowed.clear();
117
state.remote = { mode: "local-exec" };
118
+ state.clientEditors = editors;
119
state.run.mockReset().mockResolvedValue(AsyncResult.success(undefined));
120
state.openUrl.mockReset().mockResolvedValue(true);
121
state.setPreferred.mockReset();
@@ -112,11 +124,21 @@ beforeEach(() => {
124
state.listeners.clear();
125
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
126
vi.stubGlobal("navigator", { platform: "Linux" });
127
+ const events = new EventTarget();
128
+ const storage = new Map<string, string>();
129
vi.stubGlobal("window", {
116
- addEventListener: (_type: string, callback: (event: KeyboardEvent) => void) => {
117
- state.keydown = callback;
130
+ localStorage: {
131
+ getItem: (key: string) => storage.get(key) ?? null,
132
+ setItem: (key: string, value: string) => storage.set(key, value),
133
+ removeItem: (key: string) => storage.delete(key),
134
+ },
135
+ dispatchEvent: (event: Event) => events.dispatchEvent(event),
136
+ addEventListener: (type: string, callback: EventListener) => {
137
+ events.addEventListener(type, callback);
138
+ if (type === "keydown") state.keydown = callback;
139
},
119
- removeEventListener: (_type: string, callback: (event: KeyboardEvent) => void) => {
140
+ removeEventListener: (type: string, callback: EventListener) => {
141
+ events.removeEventListener(type, callback);
142
if (state.keydown === callback) state.keydown = null;
143
},
144
});
@@ -128,16 +150,17 @@ afterEach(async () => {
150
vi.unstubAllGlobals();
151
});
152
131
-async function renderPicker() {
153
+async function renderPicker(availableEditors: readonly EditorId[] = editors, panel = false) {
154
await act(async () => {
155
for (const listener of state.listeners) listener();
156
const node = (
157
<OpenInPicker
158
environmentId={selected}
159
keybindings={DEFAULT_RESOLVED_KEYBINDINGS}
138
- availableEditors={editors}
160
+ availableEditors={availableEditors}
161
openInCwd="/work/project"
140
- compact
162
+ displayMode={panel ? "panel" : "toolbar"}
163
+ compact={!panel}
164
/>
165
);
166
if (renderer) renderer.update(node);
@@ -153,6 +176,37 @@ function keyboardEvent() {
176
return { preventDefault: vi.fn() } as unknown as KeyboardEvent;
177
}
178
179
+it.each(["local-exec", "remote-links"] as const)(
180
+ "selects the preferred editor without launching a %s workspace",
181
+ async (mode) => {
182
+ state.allowed.add(selected);
183
+ state.clientEditors = ["cursor", "vscode"];
184
+ state.remote =
185
+ mode === "local-exec" ? { mode } : { mode, host: { kind: "ssh-alias", host: "test-host" } };
186
+ await renderPicker(["cursor", "vscode"], true);
187
+ expect(renderer!.root.findByProps({ "aria-label": "Open in Cursor" })).toBeDefined();
188
+ await act(async () => {
189
+ renderer!.root.findByProps({ children: "VS Code" }).parent!.props.onClick();
190
+ });
191
+ expect(window.localStorage.getItem("t3code:last-editor")).toBe('"vscode"');
192
+ const openButton = renderer!.root.findByProps({ "aria-label": "Open in VS Code" });
193
+ expect(state.run).not.toHaveBeenCalled();
194
+ expect(state.openUrl).not.toHaveBeenCalled();
195
+
196
+ await act(async () => openButton.props.onClick());
197
+ if (mode === "local-exec") {
198
+ expect(state.run).toHaveBeenCalledExactlyOnceWith({
199
+ environmentId: selected,
200
+ input: { cwd: "/work/project", editor: "vscode" },
201
+ });
202
+ } else {
203
+ expect(state.openUrl).toHaveBeenCalledExactlyOnceWith(
204
+ "vscode://vscode-remote/ssh-remote+test-host/work/project",
205
+ );
206
+ }
207
+ },
208
+);
209
+
210
describe("host editor access", () => {
211
it("uses the selected grant for both the button and a retained shortcut", async () => {
212
state.allowed.add(selected);
apps/web/src/components/chat/OpenInPicker.tsx
+7
-1
@@ -340,7 +340,13 @@ export const OpenInPicker = memo(function OpenInPicker({
340
density={presentation === "menu" ? "touch" : "default"}
341
disabled={!openInCwd || !canOpenEditor}
342
key={value}
343
- onClick={() => openInEditor(value)}
343
+ onClick={() => {
344
+ if (presentation === "menu") {
345
+ void openInEditor(value);
346
+ } else {
347
+ setPreferredEditor(value);
348
+ }
349
+ }}
350
>
351
<Icon aria-hidden="true" className={getOpenInIconClass(kind)} />
352
<MenuItemLabel>{label}</MenuItemLabel>
packages/shared/src/editor.ts
+9
-3
@@ -33,11 +33,16 @@ export const resolveEditorCommand = Effect.fn("editor.resolveEditorCommand")(fun
33
) {
34
if (editor.commands === null) return Option.none();
35
const baseArgs = "baseArgs" in editor ? editor.baseArgs : [];
36
- for (const command of editor.commands) {
37
- if (yield* isCommandAvailable(command, { env })) return Option.some({ command, baseArgs });
36
+ const platform = yield* HostProcess.Platform;
37
+ // OpenZFS also installs a `zed` executable. Prefer the macOS editor bundle
38
+ // so a PATH entry for the ZFS Event Daemon cannot take over editor opens.
39
+ const preferBundle = platform === "darwin" && editor.id === "zed";
40
+ if (!preferBundle) {
41
+ for (const command of editor.commands) {
42
+ if (yield* isCommandAvailable(command, { env })) return Option.some({ command, baseArgs });
43
+ }
44
}
45
40
- const platform = yield* HostProcess.Platform;
46
const path = yield* Path.Path;
47
const fs = yield* FileSystem.FileSystem;
48
const home = env.HOME;
@@ -134,6 +139,7 @@ export const resolveEditorCommand = Effect.fn("editor.resolveEditorCommand")(fun
139
}
140
}
141
142
+ if (preferBundle) candidates.push(...editor.commands);
143
for (const candidate of candidates) {
144
if (yield* isCommandAvailable(candidate, { env })) {
145
return Option.some({