Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/zed-editor-line.md
Original file line number Diff line number Diff line change
@@ -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.
29 changes: 26 additions & 3 deletions packages/hunk/src/ui/lib/openInEditor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
});
});

Expand Down
4 changes: 4 additions & 0 deletions packages/hunk/src/ui/lib/openInEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] };
}

Expand Down