mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 15:46:26 -04:00
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.
This commit is contained in:
parent
2210a00af9
commit
63ffb829c0
|
|
@ -4,6 +4,8 @@ import (
|
|||
"path/filepath"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
||||
|
|
@ -50,6 +52,41 @@ func (self *SwitchToDiffFilesController) GetKeybindings(opts types.KeybindingsOp
|
|||
return bindings
|
||||
}
|
||||
|
||||
func (self *SwitchToDiffFilesController) GetOnClickFocusedMainView() func(mainViewName string, clickedLineIdx int) error {
|
||||
return func(mainViewName string, clickedLineIdx int) error {
|
||||
clickedFile, line, ok := self.c.Helpers().Staging.GetFileAndLineForClickedDiffLine(mainViewName, clickedLineIdx)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := self.enter(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
context := self.c.Contexts().CommitFiles
|
||||
var node *filetree.CommitFileNode
|
||||
|
||||
relativePath, err := filepath.Rel(self.c.Git().RepoPaths.WorktreePath(), clickedFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
relativePath = "./" + relativePath
|
||||
context.CommitFileTreeViewModel.ExpandToPath(relativePath)
|
||||
self.c.PostRefreshUpdate(context)
|
||||
|
||||
idx, ok := context.CommitFileTreeViewModel.GetIndexForPath(relativePath)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
context.SetSelectedLineIdx(idx)
|
||||
context.GetViewTrait().FocusPoint(
|
||||
context.ModelIndexToViewIndex(idx), false)
|
||||
node = context.GetSelected()
|
||||
return self.c.Helpers().CommitFiles.EnterCommitFile(node, types.OnFocusOpts{ClickedWindowName: "main", ClickedViewLineIdx: line, ClickedViewRealLineIdx: line})
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SwitchToDiffFilesController) Context() types.Context {
|
||||
return self.context
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue