Display unambiguous sign when hunks overlap.

See #556.
This commit is contained in:
Andy Stewart
2018-10-18 09:45:55 +01:00
parent 622193a625
commit 89c34f74cb
5 changed files with 32 additions and 1 deletions

View File

@@ -73,6 +73,7 @@ function! gitgutter#highlight#define_signs() abort
sign define GitGutterLineModified
sign define GitGutterLineRemoved
sign define GitGutterLineRemovedFirstLine
sign define GitGutterLineRemovedAboveAndBelow
sign define GitGutterLineModifiedRemoved
sign define GitGutterDummy
@@ -86,6 +87,7 @@ function! s:define_sign_text() abort
execute "sign define GitGutterLineModified text=" . g:gitgutter_sign_modified
execute "sign define GitGutterLineRemoved text=" . g:gitgutter_sign_removed
execute "sign define GitGutterLineRemovedFirstLine text=" . g:gitgutter_sign_removed_first_line
execute "sign define GitGutterLineRemovedAboveAndBelow text=" . g:gitgutter_sign_removed_above_and_below
execute "sign define GitGutterLineModifiedRemoved text=" . g:gitgutter_sign_modified_removed
endfunction
@@ -99,12 +101,14 @@ function! gitgutter#highlight#define_sign_text_highlights() abort
sign define GitGutterLineModified texthl=GitGutterChange
sign define GitGutterLineRemoved texthl=GitGutterDelete
sign define GitGutterLineRemovedFirstLine texthl=GitGutterDelete
sign define GitGutterLineRemovedAboveAndBelow texthl=GitGutterDelete
sign define GitGutterLineModifiedRemoved texthl=GitGutterChangeDelete
else
sign define GitGutterLineAdded texthl=GitGutterAddInvisible
sign define GitGutterLineModified texthl=GitGutterChangeInvisible
sign define GitGutterLineRemoved texthl=GitGutterDeleteInvisible
sign define GitGutterLineRemovedFirstLine texthl=GitGutterDeleteInvisible
sign define GitGutterLineRemovedAboveAndBelow texthl=GitGutterDeleteInvisible
sign define GitGutterLineModifiedRemoved texthl=GitGutterChangeDeleteInvisible
endif
endfunction
@@ -115,12 +119,14 @@ function! s:define_sign_line_highlights() abort
sign define GitGutterLineModified linehl=GitGutterChangeLine
sign define GitGutterLineRemoved linehl=GitGutterDeleteLine
sign define GitGutterLineRemovedFirstLine linehl=GitGutterDeleteLine
sign define GitGutterLineRemovedAboveAndBelow linehl=GitGutterDeleteLine
sign define GitGutterLineModifiedRemoved linehl=GitGutterChangeDeleteLine
else
sign define GitGutterLineAdded linehl=
sign define GitGutterLineModified linehl=
sign define GitGutterLineRemoved linehl=
sign define GitGutterLineRemovedFirstLine linehl=
sign define GitGutterLineRemovedAboveAndBelow linehl=
sign define GitGutterLineModifiedRemoved linehl=
endif
endfunction

View File

@@ -93,6 +93,9 @@ function! s:current_hunk() abort
return current_hunk
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.
function! gitgutter#hunk#cursor_in_hunk(hunk) abort
let current_line = line('.')

View File

@@ -170,7 +170,16 @@ function! s:upsert_new_gitgutter_signs(bufnr, modified_lines) abort
let other_signs = gitgutter#utility#getbufvar(a:bufnr, 'other_signs')
let old_gitgutter_signs = gitgutter#utility#getbufvar(a:bufnr, 'gitgutter_signs')
for line in a:modified_lines
" Handle special case where the first line is the site of two hunks:
" lines deleted above at the start of the file, and lines deleted below from
" the (new) second line down.
if a:modified_lines[0:1] == [[1, 'removed_first_line'], [1, 'removed']]
let modified_lines = [[1, 'removed_above_and_below'] + a:modified_lines[2:]]
else
let modified_lines = a:modified_lines
endif
for line in modified_lines
let line_number = line[0] " <number>
if index(other_signs, line_number) == -1 " don't clobber others' signs
let name = s:highlight_name_for_change(line[1])
@@ -213,6 +222,8 @@ function! s:highlight_name_for_change(text) abort
return 'GitGutterLineModified'
elseif a:text ==# 'modified_removed'
return 'GitGutterLineModifiedRemoved'
elseif a:text ==# 'removed_above_and_below'
return 'GitGutterLineRemovedAboveAndBelow'
endif
endfunction

View File

@@ -44,6 +44,7 @@ else
call s:set('g:gitgutter_sign_removed_first_line', '_^')
endif
call s:set('g:gitgutter_sign_removed_above_and_below', '[')
call s:set('g:gitgutter_sign_modified_removed', '~_')
call s:set('g:gitgutter_git_args', '')
call s:set('g:gitgutter_diff_args', '')

View File

@@ -117,6 +117,16 @@ function Test_remove_first_lines()
endfunction
function Test_overlapping_hunks()
execute '3d'
execute '1d'
call s:trigger_gitgutter()
let expected = ["line=1 id=3000 name=GitGutterLineRemovedAboveAndBelow"]
call assert_equal(expected, s:signs('fixture.txt'))
endfunction
function Test_edit_file_with_same_name_as_a_branch()
normal 5Gi*
call system('git checkout -b fixture.txt')