Preserve fold open/close status of the TOC on save.
Since TOC is completely recreated, Vim loses its fold open/close status. If your TOC was open, after you save it gets closed. Fix will save fold status, and restore it after TOC is updated.
This commit is contained in:
parent
d265df42f5
commit
0d3f526a88
@ -1147,9 +1147,12 @@ function! vimwiki#base#update_listing_in_buffer(strings, start_header,
|
|||||||
let cursor_line = old_cursor_pos[1]
|
let cursor_line = old_cursor_pos[1]
|
||||||
let is_cursor_after_listing = 0
|
let is_cursor_after_listing = 0
|
||||||
|
|
||||||
|
let is_fold_closed = 1
|
||||||
|
|
||||||
let lines_diff = 0
|
let lines_diff = 0
|
||||||
|
|
||||||
if already_there
|
if already_there
|
||||||
|
let is_fold_closed = ( foldclosed(start_lnum) > 1 )
|
||||||
" delete the old listing
|
" delete the old listing
|
||||||
let whitespaces_in_first_line = matchstr(getline(start_lnum), '\m^\s*')
|
let whitespaces_in_first_line = matchstr(getline(start_lnum), '\m^\s*')
|
||||||
let end_lnum = start_lnum + 1
|
let end_lnum = start_lnum + 1
|
||||||
@ -1189,6 +1192,12 @@ function! vimwiki#base#update_listing_in_buffer(strings, start_header,
|
|||||||
let lines_diff += 1
|
let lines_diff += 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" Open fold, if needed
|
||||||
|
if !is_fold_closed
|
||||||
|
exe start_lnum
|
||||||
|
norm zo
|
||||||
|
endif
|
||||||
|
|
||||||
if is_cursor_after_listing
|
if is_cursor_after_listing
|
||||||
let old_cursor_pos[1] += lines_diff
|
let old_cursor_pos[1] += lines_diff
|
||||||
endif
|
endif
|
||||||
|
Loading…
Reference in New Issue
Block a user