11package helpers
22
33import (
4+ "regexp"
5+
46 "github.com/jesseduffield/lazygit/pkg/commands/models"
57 "github.com/jesseduffield/lazygit/pkg/gui/patch_exploring"
68 "github.com/jesseduffield/lazygit/pkg/gui/types"
9+ "github.com/jesseduffield/lazygit/pkg/utils"
710)
811
912type StagingHelper struct {
10- c * HelperCommon
13+ c * HelperCommon
14+ windowHelper * WindowHelper
1115}
1216
1317func NewStagingHelper (
1418 c * HelperCommon ,
19+ windowHelper * WindowHelper ,
1520) * StagingHelper {
1621 return & StagingHelper {
17- c : c ,
22+ c : c ,
23+ windowHelper : windowHelper ,
1824 }
1925}
2026
@@ -30,12 +36,16 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) {
3036 }
3137
3238 mainSelectedLineIdx := - 1
39+ mainSelectedRealLineIdx := - 1
3340 secondarySelectedLineIdx := - 1
41+ secondarySelectedRealLineIdx := - 1
3442 if focusOpts .ClickedViewLineIdx > 0 {
3543 if secondaryFocused {
3644 secondarySelectedLineIdx = focusOpts .ClickedViewLineIdx
45+ secondarySelectedRealLineIdx = focusOpts .ClickedViewRealLineIdx
3746 } else {
3847 mainSelectedLineIdx = focusOpts .ClickedViewLineIdx
48+ mainSelectedRealLineIdx = focusOpts .ClickedViewRealLineIdx
3949 }
4050 }
4151
@@ -63,11 +73,11 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) {
6373 secondaryContext .GetMutex ().Lock ()
6474
6575 mainContext .SetState (
66- patch_exploring .NewState (mainDiff , mainSelectedLineIdx , mainContext .GetView (), mainContext .GetState ()),
76+ patch_exploring .NewState (mainDiff , mainSelectedLineIdx , mainSelectedRealLineIdx , mainContext .GetView (), mainContext .GetState ()),
6777 )
6878
6979 secondaryContext .SetState (
70- patch_exploring .NewState (secondaryDiff , secondarySelectedLineIdx , secondaryContext .GetView (), secondaryContext .GetState ()),
80+ patch_exploring .NewState (secondaryDiff , secondarySelectedLineIdx , secondarySelectedRealLineIdx , secondaryContext .GetView (), secondaryContext .GetState ()),
7181 )
7282
7383 mainState := mainContext .GetState ()
@@ -124,3 +134,20 @@ func (self *StagingHelper) secondaryStagingFocused() bool {
124134func (self * StagingHelper ) mainStagingFocused () bool {
125135 return self .c .Context ().CurrentStatic ().GetKey () == self .c .Contexts ().Staging .GetKey ()
126136}
137+
138+ func (self * StagingHelper ) GetFileAndLineForClickedDiffLine (windowName string , lineIdx int ) (string , int , bool ) {
139+ v , _ := self .c .GocuiGui ().View (self .windowHelper .GetViewNameForWindow (windowName ))
140+ hyperlink , ok := v .HyperLinkInLine (lineIdx , "lazygit-edit:" )
141+ if ! ok {
142+ return "" , 0 , false
143+ }
144+
145+ re := regexp .MustCompile (`^lazygit-edit://(.+?):(\d+)$` )
146+ matches := re .FindStringSubmatch (hyperlink )
147+ if matches == nil {
148+ return "" , 0 , false
149+ }
150+ filepath := matches [1 ]
151+ lineNumber := utils .MustConvertToInt (matches [2 ])
152+ return filepath , lineNumber , true
153+ }
0 commit comments