mirror of
https://github.com/preservim/tagbar.git
synced 2025-02-15 05:53:00 +08:00
Correct focus on startup under certain circumstances, closes #60
This commit is contained in:
parent
08b474b59f
commit
2ba944b162
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user