Fix independent toggling of signs in sign column and line highlights.

Note that line highlighting requires signs to be placed (because the
line highlight is simply an attribute of a sign).  If the user doesn't
want to see signs in the sign column, but does want line highlighting,
then we make the signs in the sign column invisible.

If neither the signs in the sign column nor the line highlights are
needed (presumably the user just looks at the hunks stats) then we can
remove all signs, at which point Vim removes the sign column...unless
the "sign column always" option is set.
This commit is contained in:
Andy Stewart
2014-05-19 15:50:51 +02:00
parent 0759c96770
commit ceeba75239
2 changed files with 54 additions and 7 deletions

View File

@@ -23,7 +23,7 @@ function! gitgutter#process_buffer(file, realtime)
call hunk#set_hunks(diff#parse_diff(diff))
let modified_lines = diff#process_hunks(hunk#hunks())
if g:gitgutter_signs
if g:gitgutter_signs || g:gitgutter_highlight_lines
call sign#update_signs(a:file, modified_lines)
endif
@@ -77,19 +77,34 @@ endfunction
function! gitgutter#line_highlights_disable()
let g:gitgutter_highlight_lines = 0
call highlight#define_sign_line_highlights()
if !g:gitgutter_signs
call sign#clear_signs(utility#file())
call sign#remove_dummy_sign(0)
endif
redraw!
endfunction
function! gitgutter#line_highlights_enable()
let old_highlight_lines = g:gitgutter_highlight_lines
let g:gitgutter_highlight_lines = 1
call highlight#define_sign_line_highlights()
if !old_highlight_lines && !g:gitgutter_signs
call gitgutter#all()
endif
redraw!
endfunction
function! gitgutter#line_highlights_toggle()
let g:gitgutter_highlight_lines = !g:gitgutter_highlight_lines
call highlight#define_sign_line_highlights()
redraw!
if g:gitgutter_highlight_lines
call gitgutter#line_highlights_disable()
else
call gitgutter#line_highlights_enable()
endif
endfunction
" }}}
@@ -97,14 +112,24 @@ endfunction
" Signs {{{
function! gitgutter#signs_enable()
let old_signs = g:gitgutter_signs
let g:gitgutter_signs = 1
call gitgutter#all()
call highlight#define_sign_text_highlights()
if !old_signs && !g:gitgutter_highlight_lines
call gitgutter#all()
endif
endfunction
function! gitgutter#signs_disable()
let g:gitgutter_signs = 0
call sign#clear_signs(utility#file())
call sign#remove_dummy_sign(0)
call highlight#define_sign_text_highlights()
if !g:gitgutter_highlight_lines
call sign#clear_signs(utility#file())
call sign#remove_dummy_sign(0)
endif
endfunction
function! gitgutter#signs_toggle()