@@ -70,9 +70,9 @@ function! GitGutter(file, realtime)
7070 endif
7171 try
7272 if ! a: realtime || utility#has_fresh_changes (a: file )
73- let diff = diff#run_diff (a: realtime || utility#has_unsaved_changes (a: file ), 1 )
74- let s: hunks = diff#parse_diff (diff )
75- let modified_lines = diff#process_hunks (s: hunks )
73+ let diff = diff#run_diff (a: realtime || utility#has_unsaved_changes (a: file ), 1 )
74+ call hunk#set_hunks ( diff#parse_diff (diff ) )
75+ let modified_lines = diff#process_hunks (hunk# hunks() )
7676
7777 if g: gitgutter_signs
7878 call sign#update_signs (a: file , modified_lines)
@@ -175,39 +175,8 @@ command GitGutterSignsToggle call GitGutterSignsToggle()
175175
176176" Hunks: jump to next/previous {{{
177177
178- function ! GitGutterNextHunk (count )
179- if utility#is_active ()
180- let current_line = line (' .' )
181- let hunk_count = 0
182- for hunk in s: hunks
183- if hunk[2 ] > current_line
184- let hunk_count += 1
185- if hunk_count == a: count
186- execute ' normal!' hunk[2 ] . ' G'
187- break
188- endif
189- endif
190- endfor
191- endif
192- endfunction
193- command -count =1 GitGutterNextHunk call GitGutterNextHunk (<count> )
194-
195- function ! GitGutterPrevHunk (count )
196- if utility#is_active ()
197- let current_line = line (' .' )
198- let hunk_count = 0
199- for hunk in reverse (copy (s: hunks ))
200- if hunk[2 ] < current_line
201- let hunk_count += 1
202- if hunk_count == a: count
203- execute ' normal!' hunk[2 ] . ' G'
204- break
205- endif
206- endif
207- endfor
208- endif
209- endfunction
210- command -count =1 GitGutterPrevHunk call GitGutterPrevHunk (<count> )
178+ command -count =1 GitGutterNextHunk call hunk#next_hunk (<count> )
179+ command -count =1 GitGutterPrevHunk call hunk#prev_hunk (<count> )
211180
212181" }}}
213182
@@ -220,16 +189,9 @@ function! GitGutterStageHunk()
220189 " It doesn't make sense to stage a hunk otherwise.
221190 silent write
222191
223- " find current hunk (i.e. which one the cursor is in)
224- let current_hunk = []
225- let current_line = line (' .' )
226- for hunk in s: hunks
227- if current_line >= hunk[2 ] && current_line < hunk[2 ] + (hunk[3 ] == 0 ? 1 : hunk[3 ])
228- let current_hunk = hunk
229- break
230- endif
231- endfor
232- if len (current_hunk) != 4
192+ " find current hunk
193+ let current_hunk = hunk#current_hunk ()
194+ if empty (current_hunk)
233195 return
234196 endif
235197
@@ -249,18 +211,11 @@ function! GitGutterRevertHunk()
249211 if utility#is_active ()
250212 " Ensure the working copy of the file is up to date.
251213 " It doesn't make sense to stage a hunk otherwise.
252- write
253-
254- " find current hunk (i.e. which one the cursor is in)
255- let current_hunk = []
256- let current_line = line (' .' )
257- for hunk in s: hunks
258- if current_line >= hunk[2 ] && current_line < hunk[2 ] + (hunk[3 ] == 0 ? 1 : hunk[3 ])
259- let current_hunk = hunk
260- break
261- endif
262- endfor
263- if len (current_hunk) != 4
214+ silent write
215+
216+ " find current hunk
217+ let current_hunk = hunk#current_hunk ()
218+ if empty (current_hunk)
264219 return
265220 endif
266221
@@ -299,7 +254,7 @@ command GitGutterRevertHunk call GitGutterRevertHunk()
299254" `line` - refers to the line number where the change starts
300255" `count` - refers to the number of lines the change covers
301256function ! GitGutterGetHunks ()
302- return utility#is_active () ? s: hunks : []
257+ return utility#is_active () ? hunk# hunks() : []
303258endfunction
304259
305260" Returns an array that contains a summary of the current hunk status.
0 commit comments