From 1bea2ce40ad3993387e9bc9ade25c2a90a31d8a2 Mon Sep 17 00:00:00 2001 From: Tobias Mersmann Date: Sun, 18 Jul 2021 12:39:52 +0200 Subject: [PATCH] fix(update_listing_in_buffer): don't update listing if there are no changes Before updating a listing, check if the update differs from the existing state. Only then update the buffer, otherwise return early. Initial reasoning: If `let g:vimwiki_auto_toc = 1` is set, saving a buffer would always update the `contents`-section, even if there were no updates in this section. This lead to undesired undo-behavior. NOTE: this fix was only tested for the toc-listing. --- autoload/vimwiki/base.vim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index 03a2a21..060c0af 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -1521,6 +1521,12 @@ function! vimwiki#base#update_listing_in_buffer(Generator, start_header, " them right back. let foldenable_save = &l:foldenable setlocal nofoldenable + + " don't update file if there are no changes + if (join(getline(start_lnum + 2, end_lnum - 1), "") == join(a:Generator.f(), "")) + return + endif + silent exe 'keepjumps ' . start_lnum.','.string(end_lnum - 1).'delete _' let &l:foldenable = foldenable_save let lines_diff = 0 - (end_lnum - start_lnum)