From 5247de4a0bb6eea640f0535b8ff1e7ca02d753dc Mon Sep 17 00:00:00 2001 From: Ivan Tishchenko Date: Fri, 27 Nov 2015 03:20:44 +0300 Subject: [PATCH] Prevent scrolling of large folds while filesave updates TOC. During TOC update, screen sometimes scrolls -- most often I've seen this when I'm working inside large enough fold (does not fit in one screen). Fix uses winsaveview()/winrestview() instead of getpos()/setpos(). Winview pair would also manage scroll position on screen, not just cursor position in text. --- autoload/vimwiki/base.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index 2b8cabd..7968f86 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -1143,8 +1143,8 @@ function! vimwiki#base#update_listing_in_buffer(strings, start_header, return endif - let old_cursor_pos = getpos('.') - let cursor_line = old_cursor_pos[1] + let winview_save = winsaveview() + let cursor_line = winview_save.lnum let is_cursor_after_listing = 0 let is_fold_closed = 1 @@ -1199,9 +1199,9 @@ function! vimwiki#base#update_listing_in_buffer(strings, start_header, endif if is_cursor_after_listing - let old_cursor_pos[1] += lines_diff + let winview_save.lnum += lines_diff endif - call setpos('.', old_cursor_pos) + call winrestview(winview_save) endfunction "}}} " WIKI link following functions {{{