Skip to content

Commit f6912c8

Browse files
committed
WIP Click in commits view 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 a94ae81 commit f6912c8

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

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

+47
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package controllers
22

33
import (
4+
"path/filepath"
5+
6+
"github.com/jesseduffield/gocui"
7+
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
48
"github.com/jesseduffield/lazygit/pkg/gui/types"
59
)
610

@@ -47,6 +51,49 @@ func (self *SwitchToDiffFilesController) GetKeybindings(opts types.KeybindingsOp
4751
return bindings
4852
}
4953

54+
func (self *SwitchToDiffFilesController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
55+
return []*gocui.ViewMouseBinding{
56+
{
57+
ViewName: "main",
58+
Key: gocui.MouseLeft,
59+
Handler: self.onClickMain,
60+
FocusedView: self.context.GetViewName(),
61+
},
62+
}
63+
}
64+
65+
func (self *SwitchToDiffFilesController) onClickMain(opts gocui.ViewMouseBindingOpts) error {
66+
clickedFile, line, ok := self.c.Helpers().Staging.GetFileAndLineForClickedDiffLine("main", opts.Y)
67+
if !ok {
68+
return nil
69+
}
70+
71+
if err := self.enter(); err != nil {
72+
return err
73+
}
74+
75+
context := self.c.Contexts().CommitFiles
76+
var node *filetree.CommitFileNode
77+
78+
relativePath, err := filepath.Rel(self.c.Git().RepoPaths.RepoPath(), clickedFile)
79+
if err != nil {
80+
return err
81+
}
82+
context.CommitFileTreeViewModel.ExpandToPath(relativePath)
83+
self.c.PostRefreshUpdate(context)
84+
85+
idx, ok := context.CommitFileTreeViewModel.GetIndexForPath(relativePath)
86+
if !ok {
87+
return nil
88+
}
89+
90+
context.SetSelectedLineIdx(idx)
91+
context.GetViewTrait().FocusPoint(
92+
context.ModelIndexToViewIndex(idx))
93+
node = context.GetSelected()
94+
return self.c.Helpers().CommitFiles.EnterCommitFile(node, types.OnFocusOpts{ClickedWindowName: "main", ClickedViewLineIdx: opts.Y, ClickedViewRealLineIdx: line})
95+
}
96+
5097
func (self *SwitchToDiffFilesController) Context() types.Context {
5198
return self.context
5299
}

0 commit comments

Comments
 (0)