Prompt user to choose hunk when overlapping.

See #556.
This commit is contained in:
Andy Stewart
2018-10-18 15:39:55 +01:00
parent 4bd95abe6a
commit 0597380f6b
3 changed files with 73 additions and 1 deletions

View File

@@ -93,6 +93,19 @@ function! s:current_hunk() abort
return current_hunk
endfunction
" Returns truthy if the cursor is in two hunks (which can only happen if the
" cursor is on the first line and lines above have been deleted and lines
" immediately below have been deleted) or falsey otherwise.
function! s:cursor_in_two_hunks()
let hunks = gitgutter#hunk#hunks(bufnr(''))
if line('.') == 1 && len(hunks) > 1 && hunks[0][2:3] == [0, 0] && hunks[1][2:3] == [1, 0]
return 1
endif
return 0
endfunction
" A line can be in 0 or 1 hunks, with the following exception: when the first
" line(s) of a file has been deleted, and the new second line (and
" optionally below) has been deleted, the new first line is in two hunks.
@@ -161,6 +174,17 @@ function! s:hunk_op(op)
if empty(s:current_hunk())
call gitgutter#utility#warn('cursor is not in a hunk')
elseif s:cursor_in_two_hunks()
let choice = input('Choose hunk: upper or lower (u/l)? ')
" Clear input
normal! :<ESC>
if choice =~ 'u'
call a:op(gitgutter#diff#hunk_diff(bufnr, diff, 0))
elseif choice =~ 'l'
call a:op(gitgutter#diff#hunk_diff(bufnr, diff, 1))
else
call gitgutter#utility#warn('did not recognise your choice')
endif
else
call a:op(gitgutter#diff#hunk_diff(bufnr, diff))
endif