diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go index 0c033d83e..b8995e7bd 100644 --- a/pkg/gui/controllers/commits_files_controller.go +++ b/pkg/gui/controllers/commits_files_controller.go @@ -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 { diff --git a/pkg/gui/controllers/helpers/diff_helper.go b/pkg/gui/controllers/helpers/diff_helper.go index 2b892e9fe..f620aed66 100644 --- a/pkg/gui/controllers/helpers/diff_helper.go +++ b/pkg/gui/controllers/helpers/diff_helper.go @@ -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 diff --git a/pkg/integration/tests/worktree/open_file_of_branch_in_other_worktree.go b/pkg/integration/tests/worktree/open_file_of_branch_in_other_worktree.go index 27ace3234..78229d6e4 100644 --- a/pkg/integration/tests/worktree/open_file_of_branch_in_other_worktree.go +++ b/pkg/integration/tests/worktree/open_file_of_branch_in_other_worktree.go @@ -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() {