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