Skip to content

Commit

Permalink
Skip preview window when jumping to tag
Browse files Browse the repository at this point in the history
  • Loading branch information
majutsushi committed Nov 11, 2013
1 parent 78a7eee commit 290b71e
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions autoload/tagbar.vim
Expand Up @@ -2944,7 +2944,7 @@ function! s:JumpToTag(stay_in_tagbar) abort

let tagbarwinnr = winnr()

call s:GotoPreviousWindow(taginfo.fileinfo)
call s:GotoFileWindow(taginfo.fileinfo)

" Mark current position so it can be jumped back to
mark '
Expand Down Expand Up @@ -3558,29 +3558,39 @@ function! s:GetTagInfo(linenr, ignorepseudo) abort
return taginfo
endfunction

" s:GotoPreviousWindow() {{{2
" Try to switch to the previous buffer/window; if the buffer isn't currently
" shown in a window Tagbar will open it in the first window that has a
" non-special buffer in it.
function! s:GotoPreviousWindow(fileinfo) abort
" s:GotoFileWindow() {{{2
" Try to switch to the window that has Tagbar's current file loaded in it, or
" open the file in a window otherwise.
function! s:GotoFileWindow(fileinfo) abort
let tagbarwinnr = bufwinnr('__Tagbar__')

call s:winexec('wincmd p')

let filebufnr = bufnr(a:fileinfo.fpath)
if bufnr('%') != filebufnr
let filewinnr = bufwinnr(filebufnr)
if filewinnr != -1
call s:winexec(filewinnr . 'wincmd w')
else
if bufnr('%') != filebufnr || &previewwindow
" Search for the first real window that has the correct buffer loaded
" in it. Similar to bufwinnr() but skips the previewwindow.
let found = 0
for i in range(1, winnr('$'))
call s:winexec(i . 'wincmd w')
if bufnr('%') == filebufnr && !&previewwindow
let found = 1
break
endif
endfor

" If there is no window with the correct buffer loaded then load it
" into the first window that has a non-special buffer in it.
if !found
for i in range(1, winnr('$'))
call s:winexec(i . 'wincmd w')
if &buftype == ''
if &buftype == '' && !&previewwindow
execute 'buffer ' . filebufnr
break
endif
endfor
endif

" To make ctrl-w_p work we switch between the Tagbar window and the
" correct window once
call s:winexec(tagbarwinnr . 'wincmd w')
Expand Down

0 comments on commit 290b71e

Please sign in to comment.