Skip to content

Commit 8a753db

Browse files
committed
Press enter in main view of commits panel to enter patch building for clicked line
This involves first switching to the commit files view, and then entering the clicked file from there.
1 parent 1007436 commit 8a753db

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Diff for: pkg/gui/controllers/switch_to_diff_files_controller.go

+38
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package controllers
22

33
import (
4+
"path/filepath"
5+
6+
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
47
"github.com/jesseduffield/lazygit/pkg/gui/types"
58
)
69

@@ -47,6 +50,41 @@ func (self *SwitchToDiffFilesController) GetKeybindings(opts types.KeybindingsOp
4750
return bindings
4851
}
4952

53+
func (self *SwitchToDiffFilesController) GetOnClickFocusedMainView() func(mainViewName string, clickedLineIdx int) error {
54+
return func(mainViewName string, clickedLineIdx int) error {
55+
clickedFile, line, ok := self.c.Helpers().Staging.GetFileAndLineForClickedDiffLine(mainViewName, clickedLineIdx)
56+
if !ok {
57+
return nil
58+
}
59+
60+
if err := self.enter(); err != nil {
61+
return err
62+
}
63+
64+
context := self.c.Contexts().CommitFiles
65+
var node *filetree.CommitFileNode
66+
67+
relativePath, err := filepath.Rel(self.c.Git().RepoPaths.RepoPath(), clickedFile)
68+
if err != nil {
69+
return err
70+
}
71+
relativePath = "./" + relativePath
72+
context.CommitFileTreeViewModel.ExpandToPath(relativePath)
73+
self.c.PostRefreshUpdate(context)
74+
75+
idx, ok := context.CommitFileTreeViewModel.GetIndexForPath(relativePath)
76+
if !ok {
77+
return nil
78+
}
79+
80+
context.SetSelectedLineIdx(idx)
81+
context.GetViewTrait().FocusPoint(
82+
context.ModelIndexToViewIndex(idx))
83+
node = context.GetSelected()
84+
return self.c.Helpers().CommitFiles.EnterCommitFile(node, types.OnFocusOpts{ClickedWindowName: "main", ClickedViewLineIdx: line, ClickedViewRealLineIdx: line})
85+
}
86+
}
87+
5088
func (self *SwitchToDiffFilesController) Context() types.Context {
5189
return self.context
5290
}

0 commit comments

Comments
 (0)