mirror of
https://github.com/vim-airline/vim-airline.git
synced 2024-11-26 02:09:48 +08:00
branch: ignore upcoming FocusGained when updating
closes #2029 airline#util#focusgain(1) was called too soon -- it's called before vim loses focus and not after it gains focus. Instead, we ignore the next FocusGained event.
This commit is contained in:
parent
8fbb16f838
commit
dd247a0f85
|
@ -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)
|
let s:sha1size = get(g:, 'airline#extensions#branch#sha1_len', 7)
|
||||||
|
|
||||||
function! s:update_git_branch()
|
function! s:update_git_branch()
|
||||||
|
call airline#util#ignore_next_focusgain()
|
||||||
if !airline#util#has_fugitive() && !airline#util#has_gina()
|
if !airline#util#has_fugitive() && !airline#util#has_gina()
|
||||||
let s:vcs_config['git'].branch = ''
|
let s:vcs_config['git'].branch = ''
|
||||||
return
|
return
|
||||||
|
@ -114,7 +115,7 @@ endfunction
|
||||||
function! s:display_git_branch()
|
function! s:display_git_branch()
|
||||||
" disable FocusGained autocommand, might cause loops because system() causes
|
" disable FocusGained autocommand, might cause loops because system() causes
|
||||||
" a refresh, which causes a system() command again #2029
|
" 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
|
let name = b:buffer_vcs_config['git'].branch
|
||||||
try
|
try
|
||||||
let commit = matchstr(FugitiveParse()[0], '^\x\+')
|
let commit = matchstr(FugitiveParse()[0], '^\x\+')
|
||||||
|
@ -131,7 +132,6 @@ function! s:display_git_branch()
|
||||||
endif
|
endif
|
||||||
catch
|
catch
|
||||||
endtry
|
endtry
|
||||||
call airline#util#focusgain(1)
|
|
||||||
return name
|
return name
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
|
@ -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:nomodeline = (v:version > 703 || (v:version == 703 && has("patch438"))) ? '<nomodeline>' : ''
|
||||||
let s:has_strchars = exists('*strchars')
|
let s:has_strchars = exists('*strchars')
|
||||||
let s:has_strcharpart = exists('*strcharpart')
|
let s:has_strcharpart = exists('*strcharpart')
|
||||||
let s:focusgained_enabled = 0
|
let s:focusgained_ignored = 0
|
||||||
|
|
||||||
" TODO: Try to cache winwidth(0) function
|
" TODO: Try to cache winwidth(0) function
|
||||||
" e.g. store winwidth per window and access that, only update it, if the size
|
" 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)
|
\ airline#util#getbufvar(winbufnr(a:winnr), 'airline_disable_statusline', 0)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! airline#util#focusgain(allow)
|
function! airline#util#ignore_next_focusgain()
|
||||||
let s:focusgained_enabled = a:allow
|
let s:focusgained_ignored += 1
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! airline#util#focusgained_disabled()
|
function! airline#util#try_focusgained()
|
||||||
return s:focusgained_enabled < 1
|
let s:focusgained_ignored -= 1
|
||||||
|
if s:focusgained_ignored < 0
|
||||||
|
let s:focusgained_ignored = 0
|
||||||
|
endif
|
||||||
|
return s:focusgained_ignored <= 0
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
|
@ -83,10 +83,9 @@ function! s:on_window_changed(event)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:on_focus_gained()
|
function! s:on_focus_gained()
|
||||||
if airline#util#focusgained_disabled()
|
if airline#util#try_focusgained()
|
||||||
return
|
|
||||||
endif
|
|
||||||
unlet! w:airline_lastmode | :call <sid>airline_refresh(1)
|
unlet! w:airline_lastmode | :call <sid>airline_refresh(1)
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:on_cursor_moved()
|
function! s:on_cursor_moved()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user