Correct focus on startup under certain circumstances, closes #60

This commit is contained in:
Jan Larres 2012-02-23 20:42:35 +13:00
parent 08b474b59f
commit 2ba944b162

View File

@ -967,6 +967,8 @@ function! s:CreateAutocommands()
\ s:AutoUpdate(fnamemodify(expand('<afile>'), ':p'))
autocmd BufDelete,BufUnload,BufWipeout * call
\ s:CleanupFileinfo(fnamemodify(expand('<afile>'), ':p'))
autocmd VimEnter * call s:CorrectFocusOnStartup()
augroup END
let s:autocommands_done = 1
@ -1525,6 +1527,9 @@ function! s:OpenWindow(flags)
return
endif
" This is only needed for the CorrectFocusOnStartup() function
let s:last_autofocus = autofocus
if !s:Init()
return 0
endif
@ -1697,6 +1702,23 @@ function! s:ZoomWindow()
endif
endfunction
" s:CorrectFocusOnStartup() {{{2
" For whatever reason the focus will be on the Tagbar window if
" tagbar#autoopen is used with a FileType autocommand on startup and
" g:tagbar_left is set. This should work around it by jumping to the window of
" the current file after startup.
function! s:CorrectFocusOnStartup()
if bufwinnr('__Tagbar__') != -1 && !g:tagbar_autofocus && !s:last_autofocus
let curfile = s:known_files.getCurrent()
if !empty(curfile) && curfile.fpath != fnamemodify(bufname('%'), ':p')
let winnr = bufwinnr(curfile.fpath)
if winnr != -1
call s:winexec(winnr . 'wincmd w')
endif
endif
endif
endfunction
" Tag processing {{{1
" s:ProcessFile() {{{2
" Execute ctags and put the information into a 'FileInfo' object