diff --git a/internal/git/client.go b/internal/git/client.go index 43eff48..6367c71 100644 --- a/internal/git/client.go +++ b/internal/git/client.go @@ -55,7 +55,7 @@ func DiffCmd(targetBranch, path string) tea.Cmd { } } -func OpenEditorCmd(path string, lineNumber int) tea.Cmd { +func OpenEditorCmd(path string, lineNumber int, targetBranch string) tea.Cmd { editor := os.Getenv("EDITOR") if editor == "" { if _, err := exec.LookPath("nvim"); err == nil { @@ -73,6 +73,11 @@ func OpenEditorCmd(path string, lineNumber int) tea.Cmd { c := exec.Command(editor, args...) c.Stdin, c.Stdout, c.Stderr = os.Stdin, os.Stdout, os.Stderr + + // Pass the diff target branch to the editor via environment variable + // This enables plugins like difi.nvim to auto-configure the view + c.Env = append(os.Environ(), fmt.Sprintf("DIFI_TARGET=%s", targetBranch)) + return tea.ExecProcess(c, func(err error) tea.Msg { return EditorFinishedMsg{Err: err} }) diff --git a/internal/ui/model.go b/internal/ui/model.go index 456af98..aa6b595 100644 --- a/internal/ui/model.go +++ b/internal/ui/model.go @@ -184,7 +184,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { line = git.CalculateFileLine(m.diffContent, 0) } m.inputBuffer = "" - return m, git.OpenEditorCmd(m.selectedPath, line) + // Integration Point: Pass targetBranch to the editor command + return m, git.OpenEditorCmd(m.selectedPath, line, m.targetBranch) } // Viewport trigger