Fix statusline highlighting after leaving a cmdwin

Because vim doesn't trigger any autocmds after leaving a cmdwin the
statusline in the window the user returned to from the cmdwin would be
highlighted as non-current even if it should have been current.

This issue is resolved by storing the last current window ID in a script
variable, and when leaving the cmdwin we show the last current window as
current instead of detecting it after the WinEnter autocmd has been
triggered (which doesn't happen after leaving a cmdwin).

Closes #184.
This commit is contained in:
Kim Silkebækken 2013-02-06 13:18:49 +01:00
parent 2e5b9383a5
commit c2e7124da0

View File

@ -23,17 +23,25 @@ function! Powerline(winnr, current)
return s:pyeval('powerline.renderer.render('. a:winnr .', '. a:current .')') return s:pyeval('powerline.renderer.render('. a:winnr .', '. a:current .')')
endfunction endfunction
function! s:UpdateWindows() function! s:UpdateWindows(use_last_current_window_id)
if ! exists('w:window_id') if ! exists('w:window_id')
let w:window_id = s:pyeval('str(uuid.uuid4())') let w:window_id = s:pyeval('str(uuid.uuid4())')
endif endif
for winnr in range(1, winnr('$')) for winnr in range(1, winnr('$'))
call setwinvar(winnr, '&statusline', '%!Powerline('. winnr .', '. (w:window_id == getwinvar(winnr, 'window_id')) .')') let current = 0
if w:window_id == getwinvar(winnr, 'window_id') || (a:use_last_current_window_id && getwinvar(winnr, 'window_id') == s:last_current_window_id)
let current = 1
if bufname(winbufnr(winnr)) isnot# '[Command Line]'
let s:last_current_window_id = getwinvar(winnr, 'window_id')
endif
endif
call setwinvar(winnr, '&statusline', '%!Powerline('. winnr .', '. current .')')
endfor endfor
redrawstatus
endfunction endfunction
let s:last_current_window_id = ''
augroup Powerline augroup Powerline
autocmd! autocmd!
autocmd BufEnter,BufWinEnter,WinEnter,CmdwinEnter * call s:UpdateWindows() autocmd BufEnter,BufWinEnter,WinEnter,CmdwinEnter * call s:UpdateWindows(0) | redrawstatus
autocmd CmdwinLeave * call s:UpdateWindows(1)
augroup END augroup END