Improve :SignifyPreviewHunk

This commit is contained in:
Marco Hinz 2019-08-06 23:36:35 +02:00
parent ad6d7a9635
commit 801856453c
No known key found for this signature in database
GPG Key ID: 1C980A1B657B4A4F

View File

@ -297,7 +297,7 @@ function! s:preview_hunk(_sy, vcs, diff) abort
break break
endif endif
call add(hunk, line) call add(hunk, line)
elseif line[:2] == '@@ ' && s:is_line_in_hunk(line) elseif line[:2] == '@@ ' && s:is_cur_line_in_hunk(line)
let in_hunk = 1 let in_hunk = 1
endif endif
endfor endfor
@ -318,11 +318,22 @@ function! s:preview_hunk(_sy, vcs, diff) abort
noautocmd call feedkeys("\<c-w>p", 'nt') noautocmd call feedkeys("\<c-w>p", 'nt')
endfunction endfunction
function! s:is_line_in_hunk(hunkline) function! s:is_cur_line_in_hunk(hunkline) abort
let curline = line('.') let cur_line = line('.')
let [old_line, new_line, old_count, new_count] = sy#sign#parse_hunk(a:hunkline) let [old_line, new_line, _old_count, new_count] = sy#sign#parse_hunk(a:hunkline)
if curline >= new_line && curline < (new_line + new_count) if cur_line == 1 && new_line == 0
" deleted first line
return 1
endif
if cur_line == new_line && new_line < old_line
" deleted lines
return 1
endif
if cur_line >= new_line && cur_line < (new_line + new_count)
" added/changed lines
return 1 return 1
endif endif