@@ -28,6 +28,12 @@ type State struct {
28
28
viewLineIndices []int
29
29
// Array of indices of the original patch lines indexed by a wrapped view line index
30
30
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
31
37
}
32
38
33
39
// these represent what select mode we're in
@@ -65,6 +71,11 @@ func NewState(diff string, selectedLineIdx int, view *gocui.View, oldState *Stat
65
71
selectMode = HUNK
66
72
}
67
73
74
+ userEnabledHunkMode := false
75
+ if oldState != nil {
76
+ userEnabledHunkMode = oldState .userEnabledHunkMode
77
+ }
78
+
68
79
// 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
69
80
if selectedLineIdx >= 0 {
70
81
// 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
84
95
}
85
96
86
97
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 ,
95
107
}
96
108
}
97
109
@@ -129,6 +141,7 @@ func (s *State) ToggleSelectHunk() {
129
141
s .selectMode = LINE
130
142
} else {
131
143
s .selectMode = HUNK
144
+ s .userEnabledHunkMode = true
132
145
133
146
// If we are not currently on a change line, select the next one (or the
134
147
// previous one if there is no next one):
@@ -159,6 +172,10 @@ func (s *State) SelectingHunk() bool {
159
172
return s .selectMode == HUNK
160
173
}
161
174
175
+ func (s * State ) SelectingHunkEnabledByUser () bool {
176
+ return s .selectMode == HUNK && s .userEnabledHunkMode
177
+ }
178
+
162
179
func (s * State ) SelectingRange () bool {
163
180
return s .selectMode == RANGE && (s .rangeIsSticky || s .rangeStartLineIdx != s .selectedLineIdx )
164
181
}
0 commit comments