Open files with o from the worktree that has the branch checked out

Do the same for `o` in the commit files panel as the previous commits
do for `e`. If the panel was entered from a branch that another worktree
has checked out, open the file from that worktree.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Stefan Haller
2026-10-10 13:58:05 +02:00
co-authored by Claude Opus 5.5
parent 6c4409b712
commit 690509a8cc
3 changed files with 8 additions and 4 deletions
@@ -428,7 +428,7 @@ func (self *CommitFilesController) canDiscardFileChanges(nodes []*filetree.Commi
}
func (self *CommitFilesController) open(node *filetree.CommitFileNode) error {
return self.c.Helpers().Files.OpenFile(node.GetPath())
return self.c.Helpers().Diff.OpenFileOfDiff(node.GetPath())
}
func (self *CommitFilesController) edit(nodes []*filetree.CommitFileNode) error {
@@ -245,6 +245,13 @@ func (self *DiffHelper) EditFileOfDiffAtLine(path string, lineNumber int, viewNa
return self.filesHelper.EditFileAtLine(path, lineNumber)
}
// OpenFileOfDiff opens a file of the diff that the current side panel shows with the
// default application for it. Like EditFilesOfDiff, it opens the file from the
// worktree of the diff.
func (self *DiffHelper) OpenFileOfDiff(path string) error {
return self.filesHelper.OpenFile(self.pathInWorktreeOfDiff(path))
}
// otherWorktreeOfDiff returns the path of the worktree to open files of the diff in
// the current side panel from, if that isn't the current worktree. If the diff is of a
// commit of a branch, and another worktree has that branch checked out, that is the
@@ -47,10 +47,7 @@ var OpenFileOfBranchInOtherWorktree = NewIntegrationTest(NewIntegrationTestArgs{
).
Press(keys.Universal.OpenFile).
Tap(func() {
/* EXPECTED:
t.FileSystem().FileContent("open-command", Contains("/linked-worktree/file.txt\n"))
ACTUAL: */
t.FileSystem().FileContent("open-command", Contains("/repo/file.txt\n"))
}).
Press(keys.Files.CopyFileInfoToClipboard).
Tap(func() {