Clear the tick on hidden buffers when gitgutter#all(1) is called.

This should allow hidden buffers to recalculate their diff when loaded
after a FocusGained event fires.
This commit is contained in:
John Drouhard
2018-06-28 17:37:26 -05:00
committed by Andy Stewart
parent 64663ab24f
commit b2be779ced
2 changed files with 21 additions and 48 deletions

View File

@@ -3,11 +3,19 @@ let s:t_string = type('')
" Primary functions {{{
function! gitgutter#all(force) abort
for bufnr in s:uniq(tabpagebuflist())
let file = expand('#'.bufnr.':p')
if !empty(file)
call gitgutter#init_buffer(bufnr)
call gitgutter#process_buffer(bufnr, a:force)
let visible = tabpagebuflist()
for bufnr in range(1, bufnr('$') + 1)
if buflisted(bufnr)
let file = expand('#'.bufnr.':p')
if !empty(file)
if index(visible, bufnr) != -1
call gitgutter#init_buffer(bufnr)
call gitgutter#process_buffer(bufnr, a:force)
elseif a:force
call s:reset_tick(bufnr)
endif
endif
endif
endfor
endfunction
@@ -52,15 +60,12 @@ endfunction
function! gitgutter#disable() abort
" get list of all buffers (across all tabs)
let buflist = []
for i in range(tabpagenr('$'))
call extend(buflist, tabpagebuflist(i + 1))
endfor
for bufnr in s:uniq(buflist)
let file = expand('#'.bufnr.':p')
if !empty(file)
call s:clear(bufnr)
for bufnr in range(1, bufnr('$') + 1)
if buflisted(bufnr)
let file = expand('#'.bufnr.':p')
if !empty(file)
call s:clear(bufnr)
endif
endif
endfor
@@ -132,19 +137,3 @@ function! s:clear(bufnr)
call gitgutter#hunk#reset(a:bufnr)
call s:reset_tick(a:bufnr)
endfunction
if exists('*uniq') " Vim 7.4.218
function! s:uniq(list)
return uniq(sort(a:list))
endfunction
else
function! s:uniq(list)
let processed = []
for e in a:list
if index(processed, e) == -1
call add(processed, e)
endif
endfor
return processed
endfunction
endif

View File

@@ -173,26 +173,10 @@ nnoremap <silent> <Plug>GitGutterPreviewHunk :GitGutterPreviewHunk<CR>
" }}}
function! s:flag_inactive_tabs()
let active_tab = tabpagenr()
for i in range(1, tabpagenr('$'))
if i != active_tab
call settabvar(i, 'gitgutter_force', 1)
endif
endfor
endfunction
function! s:on_bufenter()
if exists('t:gitgutter_didtabenter') && t:gitgutter_didtabenter
let t:gitgutter_didtabenter = 0
let force = !g:gitgutter_terminal_reports_focus
if exists('t:gitgutter_force') && t:gitgutter_force
let t:gitgutter_force = 0
let force = 1
endif
call gitgutter#all(force)
call gitgutter#all(!g:gitgutter_terminal_reports_focus)
else
call gitgutter#init_buffer(bufnr(''))
call gitgutter#process_buffer(bufnr(''), !g:gitgutter_terminal_reports_focus)
@@ -216,7 +200,7 @@ augroup gitgutter
" vim -o file1 file2
autocmd VimEnter * if winnr() != winnr('$') | call gitgutter#all(0) | endif
autocmd FocusGained * call gitgutter#all(1) | call s:flag_inactive_tabs()
autocmd FocusGained * call gitgutter#all(1)
autocmd ColorScheme * call gitgutter#highlight#define_sign_column_highlight() | call gitgutter#highlight#define_highlights()