summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2024-10-11 16:44:59 +0200
committerStefan Haller <stefan@haller-berlin.de>2024-10-13 17:25:57 +0200
commita20477db248da422259fa344a15853233791e9ce (patch)
tree878869a9fe883b2d73e09746d66fa282ab18523c
parent29a4e99988304da31a46d33bd50dfc8ea33d2fff (diff)
WIP Click in commits view to enter patch building for clicked lineuse-delta-hyperlinks-for-clicking-in-diff
This involves first switching to the commit files view, and then entering the clicked file from there.
-rw-r--r--pkg/gui/controllers/switch_to_diff_files_controller.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/pkg/gui/controllers/switch_to_diff_files_controller.go b/pkg/gui/controllers/switch_to_diff_files_controller.go
index fc764ca7e..a5d99cc4a 100644
--- a/pkg/gui/controllers/switch_to_diff_files_controller.go
+++ b/pkg/gui/controllers/switch_to_diff_files_controller.go
@@ -1,6 +1,10 @@
package controllers
import (
+ "path/filepath"
+
+ "github.com/jesseduffield/gocui"
+ "github.com/jesseduffield/lazygit/pkg/gui/filetree"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -47,6 +51,49 @@ func (self *SwitchToDiffFilesController) GetKeybindings(opts types.KeybindingsOp
return bindings
}
+func (self *SwitchToDiffFilesController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
+ return []*gocui.ViewMouseBinding{
+ {
+ ViewName: "main",
+ Key: gocui.MouseLeft,
+ Handler: self.onClickMain,
+ FocusedView: self.context.GetViewName(),
+ },
+ }
+}
+
+func (self *SwitchToDiffFilesController) onClickMain(opts gocui.ViewMouseBindingOpts) error {
+ clickedFile, line, ok := self.c.Helpers().Staging.GetFileAndLineForClickedDiffLine("main", opts.Y)
+ 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.RepoPath(), clickedFile)
+ if err != nil {
+ return err
+ }
+ 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))
+ node = context.GetSelected()
+ return self.c.Helpers().CommitFiles.EnterCommitFile(node, types.OnFocusOpts{ClickedWindowName: "main", ClickedViewLineIdx: opts.Y, ClickedViewRealLineIdx: line})
+}
+
func (self *SwitchToDiffFilesController) Context() types.Context {
return self.context
}