@@ -28,6 +28,12 @@ type State struct {
2828 viewLineIndices []int
2929 // Array of indices of the original patch lines indexed by a wrapped view line index
3030 patchLineIndices []int
31+
32+ // whether the user has switched to hunk mode manually; if hunk mode is on
33+ // but this is false, then hunk mode was enabled because the config makes it
34+ // on by default.
35+ // this makes a difference for whether we want to escape out of hunk mode
36+ userEnabledHunkMode bool
3137}
3238
3339// these represent what select mode we're in
@@ -65,6 +71,11 @@ func NewState(diff string, selectedLineIdx int, view *gocui.View, oldState *Stat
6571 selectMode = HUNK
6672 }
6773
74+ userEnabledHunkMode := false
75+ if oldState != nil {
76+ userEnabledHunkMode = oldState .userEnabledHunkMode
77+ }
78+
6879 // if we have clicked from the outside to focus the main view we'll pass in a non-negative line index so that we can instantly select that line
6980 if selectedLineIdx >= 0 {
7081 // Clamp to the number of wrapped view lines; index might be out of
@@ -84,14 +95,15 @@ func NewState(diff string, selectedLineIdx int, view *gocui.View, oldState *Stat
8495 }
8596
8697 return & State {
87- patch : patch ,
88- selectedLineIdx : selectedLineIdx ,
89- selectMode : selectMode ,
90- rangeStartLineIdx : rangeStartLineIdx ,
91- rangeIsSticky : false ,
92- diff : diff ,
93- viewLineIndices : viewLineIndices ,
94- patchLineIndices : patchLineIndices ,
98+ patch : patch ,
99+ selectedLineIdx : selectedLineIdx ,
100+ selectMode : selectMode ,
101+ rangeStartLineIdx : rangeStartLineIdx ,
102+ rangeIsSticky : false ,
103+ diff : diff ,
104+ viewLineIndices : viewLineIndices ,
105+ patchLineIndices : patchLineIndices ,
106+ userEnabledHunkMode : userEnabledHunkMode ,
95107 }
96108}
97109
@@ -129,6 +141,7 @@ func (s *State) ToggleSelectHunk() {
129141 s .selectMode = LINE
130142 } else {
131143 s .selectMode = HUNK
144+ s .userEnabledHunkMode = true
132145
133146 // If we are not currently on a change line, select the next one (or the
134147 // previous one if there is no next one):
@@ -159,6 +172,10 @@ func (s *State) SelectingHunk() bool {
159172 return s .selectMode == HUNK
160173}
161174
175+ func (s * State ) SelectingHunkEnabledByUser () bool {
176+ return s .selectMode == HUNK && s .userEnabledHunkMode
177+ }
178+
162179func (s * State ) SelectingRange () bool {
163180 return s .selectMode == RANGE && (s .rangeIsSticky || s .rangeStartLineIdx != s .selectedLineIdx )
164181}
0 commit comments