mirror of
https://github.com/preservim/tagbar.git
synced 2025-10-04 22:16:16 +08:00
Clean up window switching
This commit is contained in:
@ -889,7 +889,7 @@ function! s:RestoreSession() abort
|
||||
else
|
||||
let in_tagbar = 1
|
||||
if winnr() != tagbarwinnr
|
||||
call s:winexec(tagbarwinnr . 'wincmd w')
|
||||
call s:goto_win(tagbarwinnr)
|
||||
let in_tagbar = 0
|
||||
endif
|
||||
endif
|
||||
@ -903,7 +903,7 @@ function! s:RestoreSession() abort
|
||||
call s:AutoUpdate(curfile, 0)
|
||||
|
||||
if !in_tagbar
|
||||
call s:winexec('wincmd p')
|
||||
call s:goto_win('p')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@ -1711,7 +1711,7 @@ function! s:OpenWindow(flags) abort
|
||||
let tagbarwinnr = bufwinnr('__Tagbar__')
|
||||
if tagbarwinnr != -1
|
||||
if winnr() != tagbarwinnr && jump
|
||||
call s:winexec(tagbarwinnr . 'wincmd w')
|
||||
call s:goto_win(tagbarwinnr)
|
||||
call s:HighlightTag(g:tagbar_autoshowtag != 2, 1, curline)
|
||||
endif
|
||||
call s:LogDebugMessage("OpenWindow finished, Tagbar already open")
|
||||
@ -1756,7 +1756,7 @@ function! s:OpenWindow(flags) abort
|
||||
call s:HighlightTag(g:tagbar_autoshowtag != 2, 1, curline)
|
||||
|
||||
if !(g:tagbar_autoclose || autofocus || g:tagbar_autofocus)
|
||||
call s:winexec('wincmd p')
|
||||
call s:goto_win('p')
|
||||
endif
|
||||
|
||||
call s:LogDebugMessage('OpenWindow finished')
|
||||
@ -1848,10 +1848,10 @@ function! s:CloseWindow() abort
|
||||
|
||||
let curfile = s:known_files.getCurrent(0)
|
||||
|
||||
call s:winexec('close')
|
||||
close
|
||||
|
||||
" Try to jump to the correct window after closing
|
||||
call s:winexec('wincmd p')
|
||||
call s:goto_win('p')
|
||||
|
||||
if !empty(curfile)
|
||||
let filebufnr = bufnr(curfile.fpath)
|
||||
@ -1859,7 +1859,7 @@ function! s:CloseWindow() abort
|
||||
if bufnr('%') != filebufnr
|
||||
let filewinnr = bufwinnr(filebufnr)
|
||||
if filewinnr != -1
|
||||
call s:winexec(filewinnr . 'wincmd w')
|
||||
call s:goto_win(filewinnr)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
@ -1869,11 +1869,11 @@ function! s:CloseWindow() abort
|
||||
" window. Save a win-local variable in the original window so we can
|
||||
" jump back to it even if the window number changed.
|
||||
let w:tagbar_returnhere = 1
|
||||
call s:winexec(tagbarwinnr . 'wincmd w')
|
||||
call s:goto_win(tagbarwinnr)
|
||||
close
|
||||
|
||||
for window in range(1, winnr('$'))
|
||||
call s:winexec(window . 'wincmd w')
|
||||
call s:goto_win(window)
|
||||
if exists('w:tagbar_returnhere')
|
||||
unlet w:tagbar_returnhere
|
||||
break
|
||||
@ -1943,7 +1943,7 @@ function! s:CorrectFocusOnStartup() abort
|
||||
if !empty(curfile) && curfile.fpath != fnamemodify(bufname('%'), ':p')
|
||||
let winnr = bufwinnr(curfile.fpath)
|
||||
if winnr != -1
|
||||
call s:winexec(winnr . 'wincmd w')
|
||||
call s:goto_win(winnr)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
@ -2558,10 +2558,10 @@ function! s:RenderContent(...) abort
|
||||
" Get the previous window number, so that we can reproduce
|
||||
" the window entering history later. Do not run autocmd on
|
||||
" this command, make sure nothing is interfering.
|
||||
call s:winexec('noautocmd wincmd p')
|
||||
" let pprevwinnr = winnr('#') " Messes up windows for some reason
|
||||
call s:goto_win('p', 1)
|
||||
let pprevwinnr = winnr()
|
||||
|
||||
call s:winexec(tagbarwinnr . 'wincmd w')
|
||||
call s:goto_win(tagbarwinnr, 1)
|
||||
endif
|
||||
|
||||
if !empty(s:known_files.getCurrent(0)) &&
|
||||
@ -2633,8 +2633,8 @@ function! s:RenderContent(...) abort
|
||||
let &eventignore = eventignore_save
|
||||
|
||||
if !in_tagbar
|
||||
call s:winexec(pprevwinnr . 'wincmd w')
|
||||
call s:winexec(prevwinnr . 'wincmd w')
|
||||
call s:goto_win(pprevwinnr, 1)
|
||||
call s:goto_win(prevwinnr, 1)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@ -2887,13 +2887,13 @@ function! s:HighlightTag(openfolds, ...) abort
|
||||
return
|
||||
endif
|
||||
let prevwinnr = winnr()
|
||||
call s:winexec(tagbarwinnr . 'wincmd w')
|
||||
call s:goto_win(tagbarwinnr)
|
||||
|
||||
match none
|
||||
|
||||
" No tag above cursor position so don't do anything
|
||||
if tagline == 0
|
||||
call s:winexec(prevwinnr . 'wincmd w')
|
||||
call s:goto_win(prevwinnr)
|
||||
redraw
|
||||
return
|
||||
endif
|
||||
@ -2908,7 +2908,7 @@ function! s:HighlightTag(openfolds, ...) abort
|
||||
|
||||
" Parent tag line number is invalid, better don't do anything
|
||||
if tagline == 0
|
||||
call s:winexec(prevwinnr . 'wincmd w')
|
||||
call s:goto_win(prevwinnr)
|
||||
redraw
|
||||
return
|
||||
endif
|
||||
@ -2930,7 +2930,7 @@ function! s:HighlightTag(openfolds, ...) abort
|
||||
|
||||
|
||||
if a:0 <= 1 " no line explicitly given, so assume we were in the file window
|
||||
call s:winexec(prevwinnr . 'wincmd w')
|
||||
call s:goto_win(prevwinnr)
|
||||
endif
|
||||
|
||||
redraw
|
||||
@ -2993,7 +2993,7 @@ function! s:JumpToTag(stay_in_tagbar) abort
|
||||
|
||||
if a:stay_in_tagbar
|
||||
call s:HighlightTag(0)
|
||||
call s:winexec(tagbarwinnr . 'wincmd w')
|
||||
call s:goto_win(tagbarwinnr)
|
||||
redraw
|
||||
elseif g:tagbar_autoclose || autoclose
|
||||
call s:CloseWindow()
|
||||
@ -3568,7 +3568,7 @@ endfunction
|
||||
function! s:GotoFileWindow(fileinfo) abort
|
||||
let tagbarwinnr = bufwinnr('__Tagbar__')
|
||||
|
||||
call s:winexec('wincmd p')
|
||||
call s:goto_win('p')
|
||||
|
||||
let filebufnr = bufnr(a:fileinfo.fpath)
|
||||
if bufnr('%') != filebufnr || &previewwindow
|
||||
@ -3576,7 +3576,7 @@ function! s:GotoFileWindow(fileinfo) abort
|
||||
" in it. Similar to bufwinnr() but skips the previewwindow.
|
||||
let found = 0
|
||||
for i in range(1, winnr('$'))
|
||||
call s:winexec(i . 'wincmd w')
|
||||
call s:goto_win(i, 1)
|
||||
if bufnr('%') == filebufnr && !&previewwindow
|
||||
let found = 1
|
||||
break
|
||||
@ -3587,7 +3587,7 @@ function! s:GotoFileWindow(fileinfo) abort
|
||||
" 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')
|
||||
call s:goto_win(i, 1)
|
||||
if &buftype == '' && !&previewwindow
|
||||
execute 'buffer ' . filebufnr
|
||||
break
|
||||
@ -3597,8 +3597,8 @@ function! s:GotoFileWindow(fileinfo) abort
|
||||
|
||||
" To make ctrl-w_p work we switch between the Tagbar window and the
|
||||
" correct window once
|
||||
call s:winexec(tagbarwinnr . 'wincmd w')
|
||||
call s:winexec('wincmd p')
|
||||
call s:goto_win(tagbarwinnr)
|
||||
call s:goto_win('p')
|
||||
endif
|
||||
|
||||
return winnr()
|
||||
@ -3651,7 +3651,7 @@ function! s:SetStatusLine(current)
|
||||
endif
|
||||
if tagbarwinnr != winnr()
|
||||
let in_tagbar = 0
|
||||
call s:winexec(tagbarwinnr . 'wincmd w')
|
||||
call s:goto_win(tagbarwinnr)
|
||||
else
|
||||
let in_tagbar = 1
|
||||
endif
|
||||
@ -3675,7 +3675,7 @@ function! s:SetStatusLine(current)
|
||||
endif
|
||||
|
||||
if !in_tagbar
|
||||
call s:winexec('wincmd p')
|
||||
call s:goto_win('p')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@ -3687,7 +3687,7 @@ function! s:QuitIfOnlyWindow() abort
|
||||
endif
|
||||
|
||||
let curwinnr = winnr()
|
||||
call s:winexec('noautocmd ' . tagbarwinnr . 'wincmd w')
|
||||
call s:goto_win(tagbarwinnr, 1)
|
||||
|
||||
" Check if there is more than one window
|
||||
if s:NextNormalWindow() == -1
|
||||
@ -3706,7 +3706,7 @@ function! s:QuitIfOnlyWindow() abort
|
||||
endif
|
||||
endif
|
||||
|
||||
call s:winexec('noautocmd ' . curwinnr . 'wincmd w')
|
||||
call s:goto_win(curwinnr, 1)
|
||||
endfunction
|
||||
|
||||
" s:NextNormalWindow() {{{2
|
||||
@ -3745,18 +3745,18 @@ function! s:NextNormalWindow() abort
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
" s:winexec() {{{2
|
||||
function! s:winexec(cmd) abort
|
||||
" Commented out for now to see if it works without.
|
||||
" s:goto_win() {{{2
|
||||
function! s:goto_win(winnr, ...) abort
|
||||
let cmd = a:winnr == 'p' ? 'wincmd p' : a:winnr . 'wincmd w'
|
||||
let noauto = a:0 > 0 ? a:1 : 0
|
||||
|
||||
" call s:LogDebugMessage("Executing without autocommands: " . a:cmd)
|
||||
call s:LogDebugMessage("goto_win(): " . cmd . ", " . noauto)
|
||||
|
||||
" let eventignore_save = &eventignore
|
||||
" set eventignore=all
|
||||
|
||||
execute a:cmd
|
||||
|
||||
" let &eventignore = eventignore_save
|
||||
if noauto
|
||||
noautocmd execute cmd
|
||||
else
|
||||
execute cmd
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" TagbarBalloonExpr() {{{2
|
||||
|
Reference in New Issue
Block a user