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

This commit is contained in:
James Long 2026-05-24 22:40:40 -04:00 committed by GitHub
parent 5ca613e28e
commit d5f397a2da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 4 deletions

View file

@ -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)

View file

@ -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)
}

View file

@ -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",