mirror of
https://github.com/powerline/powerline.git
synced 2025-07-22 05:14:58 +02:00
Fix problem with wrong window ID/winnr after some window operations
Removed autocommands as well. Powerline() function is now responsible both for displaying powerline and for updating statuslines. No cmdwin events not triggered workaround nonsense anymore. Fixes #237 Fixes #236 Fixes #222 Fixes #232
This commit is contained in:
parent
ea56f4c26b
commit
e14f5e4208
@ -47,26 +47,28 @@ else
|
|||||||
\"endfunction"
|
\"endfunction"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
function! Powerline(winnr, current)
|
function! s:GetWinID(winnr)
|
||||||
return s:pyeval('powerline.renderer.render('. a:winnr .', '. a:current .')')
|
let r = getwinvar(a:winnr, 'window_id')
|
||||||
|
if empty(r)
|
||||||
|
let r = s:pyeval('str(uuid.uuid4())')
|
||||||
|
call setwinvar(a:winnr, 'window_id', r)
|
||||||
|
call setwinvar(a:winnr, '&statusline', '%!Powerline("'.r.'")')
|
||||||
|
endif
|
||||||
|
return r
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:UpdateWindows(use_last_current_window_id)
|
function! Powerline(window_id)
|
||||||
if ! exists('w:window_id')
|
let winidx = index(map(range(1, winnr('$')), 's:GetWinID(v:val)'), a:window_id)
|
||||||
let w:window_id = s:pyeval('str(uuid.uuid4())')
|
let current = w:window_id is# a:window_id
|
||||||
endif
|
return s:pyeval('powerline.renderer.render("'. a:window_id .'", '. winidx .', '. current .')')
|
||||||
for winnr in range(1, winnr('$'))
|
|
||||||
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
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! PowerlineNew()
|
||||||
|
return Powerline(s:GetWinID(winnr()))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
set statusline=%!PowerlineNew()
|
||||||
|
|
||||||
function! PowerlineRegisterCachePurgerEvent(event)
|
function! PowerlineRegisterCachePurgerEvent(event)
|
||||||
exec s:powerline_pycmd 'from powerline.segments.vim import launchevent as powerline_launchevent'
|
exec s:powerline_pycmd 'from powerline.segments.vim import launchevent as powerline_launchevent'
|
||||||
augroup Powerline
|
augroup Powerline
|
||||||
@ -74,10 +76,7 @@ function! PowerlineRegisterCachePurgerEvent(event)
|
|||||||
augroup END
|
augroup END
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:last_current_window_id = ''
|
|
||||||
augroup Powerline
|
augroup Powerline
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd BufEnter,BufWinEnter,WinEnter,CmdwinEnter * call s:UpdateWindows(0) | redrawstatus
|
|
||||||
autocmd CmdwinLeave * call s:UpdateWindows(1)
|
|
||||||
autocmd ColorScheme * exec s:powerline_pycmd 'powerline.renderer.reset_highlight()'
|
autocmd ColorScheme * exec s:powerline_pycmd 'powerline.renderer.reset_highlight()'
|
||||||
augroup END
|
augroup END
|
||||||
|
@ -20,21 +20,19 @@ class VimRenderer(Renderer):
|
|||||||
super(VimRenderer, self).__init__(*args, **kwargs)
|
super(VimRenderer, self).__init__(*args, **kwargs)
|
||||||
self.hl_groups = {}
|
self.hl_groups = {}
|
||||||
|
|
||||||
def render(self, winnr, current):
|
def render(self, window_id, winidx, current):
|
||||||
'''Render all segments.
|
'''Render all segments.
|
||||||
|
|
||||||
This method handles replacing of the percent placeholder for vim
|
This method handles replacing of the percent placeholder for vim
|
||||||
statuslines, and it caches segment contents which are retrieved and
|
statuslines, and it caches segment contents which are retrieved and
|
||||||
used in non-current windows.
|
used in non-current windows.
|
||||||
'''
|
'''
|
||||||
window_id = vim_getwinvar(winnr, 'window_id')
|
|
||||||
if current:
|
if current:
|
||||||
mode = vim_mode()
|
mode = vim_mode()
|
||||||
else:
|
else:
|
||||||
mode = 'nc'
|
mode = 'nc'
|
||||||
segment_info = {
|
segment_info = {
|
||||||
'window': vim.windows[winnr - 1],
|
'window': vim.windows[winidx],
|
||||||
'winnr': winnr,
|
|
||||||
'mode': mode,
|
'mode': mode,
|
||||||
'window_id': window_id,
|
'window_id': window_id,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user