Return early when pre-condition not met

This commit is contained in:
Andy Stewart
2020-07-28 10:16:47 +01:00
parent 63941de9f9
commit 62ff20f979

View File

@@ -46,12 +46,14 @@ endfunction
function! gitgutter#hunk#next_hunk(count) abort
let bufnr = bufnr('')
if gitgutter#utility#is_active(bufnr)
if !gitgutter#utility#is_active(bufnr) | return | endif
let hunks = gitgutter#hunk#hunks(bufnr)
if empty(hunks)
call gitgutter#utility#warn('No hunks in file')
return
endif
let current_line = line('.')
let hunk_count = 0
for hunk in hunks
@@ -64,17 +66,18 @@ function! gitgutter#hunk#next_hunk(count) abort
endif
endfor
call gitgutter#utility#warn('No more hunks')
endif
endfunction
function! gitgutter#hunk#prev_hunk(count) abort
let bufnr = bufnr('')
if gitgutter#utility#is_active(bufnr)
if !gitgutter#utility#is_active(bufnr) | return | endif
let hunks = gitgutter#hunk#hunks(bufnr)
if empty(hunks)
call gitgutter#utility#warn('No hunks in file')
return
endif
let current_line = line('.')
let hunk_count = 0
for hunk in reverse(copy(hunks))
@@ -88,7 +91,6 @@ function! gitgutter#hunk#prev_hunk(count) abort
endif
endfor
call gitgutter#utility#warn('No previous hunks')
endif
endfunction
" Returns the hunk the cursor is currently in or an empty list if the cursor