diff --git a/.changeset/zed-editor-line.md b/.changeset/zed-editor-line.md new file mode 100644 index 000000000..c708b181b --- /dev/null +++ b/.changeset/zed-editor-line.md @@ -0,0 +1,5 @@ +--- +"hunkdiff": patch +--- + +Pass the selected line to Zed (`zed` and `zeditor`) when opening a file with `e`, matching the existing Helix support. diff --git a/packages/hunk/src/ui/lib/openInEditor.test.ts b/packages/hunk/src/ui/lib/openInEditor.test.ts index 81512e48f..9baee9469 100644 --- a/packages/hunk/src/ui/lib/openInEditor.test.ts +++ b/packages/hunk/src/ui/lib/openInEditor.test.ts @@ -95,16 +95,39 @@ describe("open in editor helpers", () => { }); }); + test("builds path:line targets for zed and zeditor", () => { + expect( + buildEditorCommand({ + editor: "zed --wait", + filePath: "/tmp/project/file.ts", + line: 123, + }), + ).toEqual({ + command: "zed", + args: ["--wait", "/tmp/project/file.ts:123"], + }); + expect( + buildEditorCommand({ + editor: "zeditor", + filePath: "/tmp/project/file.ts", + line: 123, + }), + ).toEqual({ + command: "zeditor", + args: ["/tmp/project/file.ts:123"], + }); + }); + test("defaults unknown editors to opening the file path only", () => { expect( buildEditorCommand({ - editor: "zed --new-window", + editor: "unknown-editor --flag", filePath: "/tmp/project/example.ts", line: 4, }), ).toEqual({ - command: "zed", - args: ["--new-window", "/tmp/project/example.ts"], + command: "unknown-editor", + args: ["--flag", "/tmp/project/example.ts"], }); }); diff --git a/packages/hunk/src/ui/lib/openInEditor.ts b/packages/hunk/src/ui/lib/openInEditor.ts index 21f0ed2dc..956a135b5 100644 --- a/packages/hunk/src/ui/lib/openInEditor.ts +++ b/packages/hunk/src/ui/lib/openInEditor.ts @@ -131,6 +131,10 @@ export function buildEditorCommand({ return { command, args: [...editorArgs, `${filePath}:${line}`] }; } + if (program === "zed" || program === "zeditor") { + return { command, args: [...editorArgs, `${filePath}:${line}`] }; + } + return { command, args: [...editorArgs, filePath] }; }