Просмотр исходного кода

fix(tui): open external editor in worktree cwd (#29130)

James Long 3 месяцев назад
Родитель
Сommit
d5f397a2da

+ 5 - 1
packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

@@ -509,7 +509,11 @@ export function Prompt(props: PromptProps) {
           const nonTextParts = store.prompt.parts.filter((p) => p.type !== "text")
 
           const value = text
-          const content = await Editor.open({ value, renderer })
+          const content = await Editor.open({
+            value,
+            renderer,
+            cwd: project.instance.path().worktree || project.instance.directory() || process.cwd(),
+          })
           if (!content) return
 
           input.setText(content)

+ 10 - 2
packages/opencode/src/cli/cmd/tui/routes/session/index.tsx

@@ -965,7 +965,11 @@ export function Session() {
 
           if (options.openWithoutSaving) {
             // Just open in editor without saving
-            await Editor.open({ value: transcript, renderer })
+            await Editor.open({
+              value: transcript,
+              renderer,
+              cwd: project.instance.path().worktree || project.instance.directory() || process.cwd(),
+            })
           } else {
             const exportDir = process.cwd()
             const filename = options.filename.trim()
@@ -974,7 +978,11 @@ export function Session() {
             await Filesystem.write(filepath, transcript)
 
             // Open with EDITOR if available
-            const result = await Editor.open({ value: transcript, renderer })
+            const result = await Editor.open({
+              value: transcript,
+              renderer,
+              cwd: project.instance.path().worktree || project.instance.directory() || process.cwd(),
+            })
             if (result !== undefined) {
               await Filesystem.write(filepath, result)
             }

+ 2 - 1
packages/opencode/src/cli/cmd/tui/util/editor.ts

@@ -6,7 +6,7 @@ import { CliRenderer } from "@opentui/core"
 import { Filesystem } from "@/util/filesystem"
 import { Process } from "@/util/process"
 
-export async function open(opts: { value: string; renderer: CliRenderer }): Promise<string | undefined> {
+export async function open(opts: { value: string; renderer: CliRenderer; cwd?: string }): Promise<string | undefined> {
   const editor = process.env["VISUAL"] || process.env["EDITOR"]
   if (!editor) return
 
@@ -19,6 +19,7 @@ export async function open(opts: { value: string; renderer: CliRenderer }): Prom
   try {
     const parts = editor.split(" ")
     const proc = Process.spawn([...parts, filepath], {
+      cwd: opts.cwd,
       stdin: "inherit",
       stdout: "inherit",
       stderr: "inherit",