1
0
mirror of https://github.com/gryf/tagbar.git synced 2025-12-18 03:50:26 +01:00

Save the view when redisplaying the same file to avoid distracting jumps (idea taken from NERDTree)

This commit is contained in:
Jan Larres
2011-03-22 01:36:28 +13:00
parent 3cd371910a
commit 151832d234

View File

@@ -1379,6 +1379,13 @@ function! s:RenderContent(fname, ftype)
let lazyredraw_save = &lazyredraw
set lazyredraw
if a:fname == s:current_file
" We're redisplaying the same file, so save the view
let saveline = line('.')
let savecol = col('.')
let topline = line('w0')
endif
setlocal modifiable
silent! %delete _
@@ -1488,10 +1495,21 @@ function! s:RenderContent(fname, ftype)
setlocal nomodifiable
" Make sure as much of the Tagbar content as possible is shown in the
" window by jumping to the top after drawing
execute 1
call winline()
if a:fname == s:current_file
let scrolloff_save = &scrolloff
set scrolloff=0
call cursor(topline, 1)
normal! zt
call cursor(saveline, savecol)
let &scrolloff = scrolloff_save
else
" Make sure as much of the Tagbar content as possible is shown in the
" window by jumping to the top after drawing
execute 1
call winline()
endif
let &lazyredraw = lazyredraw_save