Fix RenameFile with relative to root (prefix with /) #617
This commit is contained in:
@@ -1285,10 +1285,11 @@ function! s:update_wiki_links(wiki_nr, dir, old_url, new_url) abort
|
||||
" Param: wiki_nr <int> to get the syntax template
|
||||
" Param: old_location <string> relative to the current wiki fsource
|
||||
function! s:compute_old_url_r(wiki_nr, old_location) abort
|
||||
" TODO this may be helped by path_to_regex
|
||||
" Start, Read param
|
||||
let old_url_r = a:old_location
|
||||
" Escape the '\\/'
|
||||
let old_url_r = escape(old_url_r, '\/')
|
||||
" Replace / -> [\\/]
|
||||
let old_url_r = substitute(old_url_r, '/', '[\\\\/]', 'g')
|
||||
" Add potential ./
|
||||
let old_url_r = '\%(\.[/\\]\)\?' . old_url_r
|
||||
" Compute old url regex with filename between \zs and \ze
|
||||
@@ -1322,15 +1323,28 @@ function! s:update_wiki_links(wiki_nr, dir, old_url, new_url) abort
|
||||
|
||||
" Old url
|
||||
" Avoid E713
|
||||
let key = empty(dir_rel_fsource) ? 'NaF' : dir_rel_fsource
|
||||
let old_rel_fsource = dir_rel_fsource . a:old_url
|
||||
let key = empty(old_rel_fsource) ? 'NaF' : old_rel_fsource
|
||||
if index(keys(cache_dict), key) == -1
|
||||
let cache_dict[key] = s:compute_old_url_r(
|
||||
\ a:wiki_nr, dir_rel_fsource . a:old_url)
|
||||
\ a:wiki_nr, old_rel_fsource)
|
||||
endif
|
||||
let old_url_r = cache_dict[key]
|
||||
let r_old_rel_fsource = cache_dict[key]
|
||||
|
||||
" Update url in source file
|
||||
call s:update_wiki_link(fsource, old_url_r, new_url)
|
||||
call s:update_wiki_link(fsource, r_old_rel_fsource, new_url)
|
||||
|
||||
" Same job with absolute path (#617)
|
||||
let old_rel_root = '/' . dir_rel_root . '/' . a:old_url
|
||||
let key = empty(dir_rel_root) ? 'NaF' : dir_rel_root
|
||||
if index(keys(cache_dict), key) == -1
|
||||
let cache_dict[key] = s:compute_old_url_r(
|
||||
\ a:wiki_nr, old_rel_root)
|
||||
endif
|
||||
let r_old_rel_root = cache_dict[key]
|
||||
let new_rel_root = simplify('/' . dir_rel_root . '/' . a:new_url)
|
||||
|
||||
call s:update_wiki_link(fsource, r_old_rel_root, new_rel_root)
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -13,8 +13,24 @@ Execute (Mkdir dir1 dir2 dir11 dir12):
|
||||
call system("mkdir $HOME/testmarkdown/dir2")
|
||||
|
||||
|
||||
# Test Transdirectory and argument {{{1
|
||||
# New feature #926
|
||||
|
||||
Do(Link with / are relative to root #617):
|
||||
:edit $HOME/testmarkdown/test.md\<Cr>
|
||||
:Log 'Is this wiki 2'\<Cr>
|
||||
:AssertEqual 1, vimwiki#vars#get_bufferlocal('wiki_nr')\<Cr>
|
||||
:Log 'Editing'\<Cr>
|
||||
i/dir1/old_name\<Esc>
|
||||
\<CR>\<CR>
|
||||
:AssertEqual 'old_name', expand('%:t:r')\<Cr>
|
||||
:call WriteMe()\<Cr>
|
||||
:VimwikiRenameFile new_name\<Cr>
|
||||
:AssertEqual 'new_name', expand('%:t:r')\<Cr>
|
||||
:edit $HOME/testmarkdown/test.md\<Cr>
|
||||
:AssertEqual '[dir1 old_name](/dir1/new_name)', getline(1)\<Cr>
|
||||
|
||||
|
||||
# TEST TRANSDIRECTORY AND ARGUMENT {{{1
|
||||
# NEW FEATURE #926
|
||||
|
||||
# Create smaller unit {{{2
|
||||
|
||||
@@ -83,9 +99,10 @@ Do (Testing transforward {{{2):
|
||||
0\<Cr>\<Cr>
|
||||
|
||||
# Now in root
|
||||
:AssertEqual expand('%'), $HOME . '/testmarkdown/Test-Rename-Completion.md'\<Cr>
|
||||
:AssertEqual $HOME . '/testmarkdown/Test-Rename-Completion.md', expand('%')\<Cr>
|
||||
:VimwikiRenameFile dir1/Test-Rename-Completion-2\<Cr>
|
||||
:AssertEqual expand('%'), $HOME . '/testmarkdown/dir1/Test-Rename-Completion-2.md'\<Cr>
|
||||
:Log 'Rename -> dir1/Test...{{{3'\<Cr>
|
||||
:AssertEqual $HOME . '/testmarkdown/dir1/Test-Rename-Completion-2.md', expand('%')\<Cr>
|
||||
|
||||
|
||||
Execute (Delete smaller unit changed {{{2):
|
||||
|
||||
Reference in New Issue
Block a user