From 56bee63e17924852caf19eb28b7173e5b6b5b4e9 Mon Sep 17 00:00:00 2001 From: Jan Larres Date: Sat, 29 Oct 2016 17:29:40 +1300 Subject: [PATCH] Only jump to previous window if there is one, closes #355 --- autoload/tagbar.vim | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index 04cb72c..5ace4b8 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -1849,14 +1849,19 @@ function! s:OpenWindow(flags) abort " since the window number can change due to the Tagbar window opening if exists('*win_getid') let prevwinid = win_getid() - call s:goto_win('p', 1) - let pprevwinid = win_getid() + if winnr('$') > 1 + call s:goto_win('p', 1) + let pprevwinid = win_getid() + call s:goto_win('p', 1) + endif else let prevwinnr = winnr() - call s:goto_win('p', 1) - let pprevwinnr = winnr() + if winnr('$') > 1 + call s:goto_win('p', 1) + let pprevwinnr = winnr() + call s:goto_win('p', 1) + endif endif - call s:goto_win('p', 1) " This is only needed for the CorrectFocusOnStartup() function let s:last_autofocus = autofocus @@ -1903,7 +1908,9 @@ function! s:OpenWindow(flags) abort if !(g:tagbar_autoclose || autofocus || g:tagbar_autofocus) if exists('*win_getid') - noautocmd call win_gotoid(pprevwinid) + if exists('pprevwinid') + noautocmd call win_gotoid(pprevwinid) + endif call win_gotoid(prevwinid) else " If the Tagbar winnr is identical to one of the saved values @@ -1913,7 +1920,9 @@ function! s:OpenWindow(flags) abort if winnr() == pprevwinnr || winnr() == prevwinnr call s:goto_win('p') else - call s:goto_win(pprevwinnr, 1) + if exists('pprevwinnr') + call s:goto_win(pprevwinnr, 1) + endif call s:goto_win(prevwinnr) endif endif