Merge pull request #2053 from idbrii/fix-focusgained

branch: ignore upcoming FocusGained when updating
This commit is contained in:
Christian Brabandt 2020-01-29 08:13:53 +01:00 committed by GitHub
commit abf54b60a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 10 deletions

View File

@ -85,6 +85,7 @@ let s:names = {'0': 'index', '1': 'orig', '2':'fetch', '3':'merge'}
let s:sha1size = get(g:, 'airline#extensions#branch#sha1_len', 7)
function! s:update_git_branch()
call airline#util#ignore_next_focusgain()
if !airline#util#has_fugitive() && !airline#util#has_gina()
let s:vcs_config['git'].branch = ''
return
@ -114,7 +115,7 @@ endfunction
function! s:display_git_branch()
" disable FocusGained autocommand, might cause loops because system() causes
" a refresh, which causes a system() command again #2029
call airline#util#focusgain(0)
call airline#util#ignore_next_focusgain()
let name = b:buffer_vcs_config['git'].branch
try
let commit = matchstr(FugitiveParse()[0], '^\x\+')
@ -131,7 +132,6 @@ function! s:display_git_branch()
endif
catch
endtry
call airline#util#focusgain(1)
return name
endfunction

View File

@ -11,7 +11,7 @@ let s:spc = g:airline_symbols.space
let s:nomodeline = (v:version > 703 || (v:version == 703 && has("patch438"))) ? '<nomodeline>' : ''
let s:has_strchars = exists('*strchars')
let s:has_strcharpart = exists('*strcharpart')
let s:focusgained_enabled = 0
let s:focusgained_ignored = 0
" TODO: Try to cache winwidth(0) function
" e.g. store winwidth per window and access that, only update it, if the size
@ -192,10 +192,15 @@ function! airline#util#stl_disabled(winnr)
\ airline#util#getbufvar(winbufnr(a:winnr), 'airline_disable_statusline', 0)
endfunction
function! airline#util#focusgain(allow)
let s:focusgained_enabled = a:allow
function! airline#util#ignore_next_focusgain()
let s:focusgained_ignored += 1
endfunction
function! airline#util#focusgained_disabled()
return s:focusgained_enabled < 1
function! airline#util#try_focusgained()
let s:focusgained_ignored -= 1
if s:focusgained_ignored < 0
let s:focusgained_ignored = 0
endif
return s:focusgained_ignored <= 0
endfunction

View File

@ -83,10 +83,9 @@ function! s:on_window_changed(event)
endfunction
function! s:on_focus_gained()
if airline#util#focusgained_disabled()
return
if airline#util#try_focusgained()
unlet! w:airline_lastmode | :call <sid>airline_refresh(1)
endif
unlet! w:airline_lastmode | :call <sid>airline_refresh(1)
endfunction
function! s:on_cursor_moved()