vimwiki

Personal wiki for vim
git clone https://github.com/vimwiki/vimwiki.git
Log | Files | Refs | README | LICENSE

commit 0693e41132525ae7ae65db86f9221accba9d8da5
parent 8a50d022b19943a53cf17b53a18d93de92f38d4e
Author: Tinmarino <tinmarino@gmail.com>
Date:   Thu,  6 Aug 2020 17:02:51 -0400

Fix: VimwikiTOC removes next non-empty line (Issue #910)

Diffstat:
Mautoload/vimwiki/base.vim | 11++++++-----
Mdoc/vimwiki.txt | 1+
Mtest/command_generate_links.vader | 4+++-
Mtest/command_toc.vader | 31+++++++++++++++++++++++++++++++
4 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim @@ -1468,8 +1468,8 @@ function! vimwiki#base#update_listing_in_buffer(Generator, start_header, " Set working range according to listing presence if already_there - let is_fold_closed = ( foldclosed(start_lnum) > -1 ) " Delete the old listing + let is_fold_closed = ( foldclosed(start_lnum) > -1 ) let whitespaces_in_first_line = matchstr(getline(start_lnum), '\m^\s*') let end_lnum = start_lnum + 1 while end_lnum <= line('$') && getline(end_lnum) =~# a:content_regex @@ -1486,6 +1486,7 @@ function! vimwiki#base#update_listing_in_buffer(Generator, start_header, let &l:foldenable = foldenable_save let lines_diff = 0 - (end_lnum - start_lnum) else + " Create new listing let start_lnum = a:default_lnum let is_cursor_after_listing = ( cursor_line > a:default_lnum ) let whitespaces_in_first_line = '' @@ -1519,9 +1520,10 @@ function! vimwiki#base#update_listing_in_buffer(Generator, start_header, endfor " Remove empty line if end of file, otherwise append if needed - if start_lnum == line('$') + let current_line = getline(start_lnum) + if start_lnum == line('$') && current_line =~# '^\s*$' silent exe 'keepjumps ' . start_lnum.'delete _' - elseif start_lnum < line('$') && getline(start_lnum) !~# '\m^\s*$' + elseif start_lnum <= line('$') && current_line !~# '\m^\s*$' keepjumps call append(start_lnum - 1, '') let lines_diff += 1 endif @@ -2491,8 +2493,7 @@ function! vimwiki#base#table_of_contents(create) abort return lines endfunction - let links_rx = '\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxListBullet').'\)' - + let links_rx = '\%(^\s*$\)\|\%(^\s*\%('.vimwiki#vars#get_syntaxlocal('rxListBullet').'\)\)' call vimwiki#base#update_listing_in_buffer( \ GeneratorTOC, \ toc_header_text, diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt @@ -3743,6 +3743,7 @@ Changed:~ Removed:~ Fixed:~ + * Issue #910: Fix: VimwikiTOC removes next non-empty line * Issue #182: VimwikiTOC support headers with link * Issue #813: iMap <Cr> interfere with completion (pum) * Issue #709: Support inline code spans inside emphasis diff --git a/test/command_generate_links.vader b/test/command_generate_links.vader @@ -35,13 +35,15 @@ Execute (VimwikiGenerateLinks x 2): call append('$', 'Last Line') VimwikiGenerateLinks -Expect (The links with a header): +Expect (The links with a header (bis)): = Generated Links = - [[buzz_bozz]] - [[index]] + Last Line + Execute (Clean Test.wiki): call DeleteFile('$HOME/testwiki/Test.wiki') diff --git a/test/command_toc.vader b/test/command_toc.vader @@ -30,6 +30,37 @@ # # Start {{{1 +Given vimwiki (One heading: May delete last line (#910) {{{1): + # Basic-title + + +Execute (VimwikiTOC x 1): + call SetSyntax('markdown') + set sw=8 + VimwikiTOC + + +Expect(Good content with 1 item x 1): + # Contents + + - [Basic-title](#basic-title) + + # Basic-title + +Execute (VimwikiTOC x 2): + call SetSyntax('markdown') + set sw=8 + VimwikiTOC + VimwikiTOC + +Expect(Good content with 1 item x 1): + # Contents + + - [Basic-title](#basic-title) + + # Basic-title + + Given vimwiki (With link header (#182) {{{1): # A [link](anything here) B # t[link](anything here)