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

@@ -332,8 +332,14 @@ endfunction
" Returns a diff for the current hunk.
function! gitgutter#diff#hunk_diff(bufnr, full_diff)
" Assumes there is only 1 current hunk unless the optional argument is given,
" in which case the cursor is in two hunks and the argument specifies the one
" to choose.
"
" Optional argument: 0 (to use the first hunk) or 1 (to use the second).
function! gitgutter#diff#hunk_diff(bufnr, full_diff, ...)
let modified_diff = []
let hunk_index = 0
let keep_line = 1
" Don't keepempty when splitting because the diff we want may not be the
" final one. Instead add trailing NL at end of function.
@@ -341,6 +347,12 @@ function! gitgutter#diff#hunk_diff(bufnr, full_diff)
let hunk_info = gitgutter#diff#parse_hunk(line)
if len(hunk_info) == 4 " start of new hunk
let keep_line = gitgutter#hunk#cursor_in_hunk(hunk_info)
if a:0 && hunk_index != a:1
let keep_line = 0
endif
let hunk_index += 1
endif
if keep_line
call add(modified_diff, line)