|
1 | 1 | package controllers
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "path/filepath" |
| 5 | + |
| 6 | + "github.com/jesseduffield/lazygit/pkg/gui/filetree" |
4 | 7 | "github.com/jesseduffield/lazygit/pkg/gui/types"
|
5 | 8 | )
|
6 | 9 |
|
@@ -47,6 +50,41 @@ func (self *SwitchToDiffFilesController) GetKeybindings(opts types.KeybindingsOp
|
47 | 50 | return bindings
|
48 | 51 | }
|
49 | 52 |
|
| 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 | + |
50 | 88 | func (self *SwitchToDiffFilesController) Context() types.Context {
|
51 | 89 | return self.context
|
52 | 90 | }
|
|
0 commit comments