Fix: Jump to nested anchor bugged with markdown (issue #1356)
This commit is contained in:
@@ -882,6 +882,9 @@ function! s:jump_to_anchor(anchor) abort
|
||||
let anchor = vimwiki#u#escape(a:anchor)
|
||||
let segments = split(anchor, '#', 0)
|
||||
|
||||
" Start at beginning => Independent of link position
|
||||
call cursor(1, 1)
|
||||
|
||||
" For markdown: there is only one segment
|
||||
for segment in segments
|
||||
" Craft segment pattern so that it is case insensitive and also matches dashes
|
||||
@@ -902,7 +905,6 @@ function! s:jump_to_segment(segment, segment_norm_re, segment_nb) abort
|
||||
" Called: jump_to_anchor with suffix and withtou suffix
|
||||
" Save cursor %% Initialize at top of line
|
||||
let oldpos = getpos('.')
|
||||
call cursor(1, 1)
|
||||
|
||||
" Get anchor regex
|
||||
let anchor_header = s:safesubstitute(
|
||||
@@ -960,9 +962,6 @@ function! s:jump_to_segment(segment, segment_norm_re, segment_nb) abort
|
||||
return 0
|
||||
endif
|
||||
|
||||
" Or keep on (i.e more than once segment)
|
||||
let oldpos = getpos('.')
|
||||
|
||||
" Said 'fail' to caller
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
# Non regression tests for issue TODO
|
||||
# -- TODO copy-paste issue description
|
||||
#
|
||||
# Syntax: https://github.com/junegunn/vader.vim#syntax-of-vader-file
|
||||
# Run: bash run_tests.sh -v -t vader -n vim_7.3.429 -f issue_example.vader
|
||||
|
||||
Given vimwiki (Input file):
|
||||
[this](#TopCategoryOne)
|
||||
[that](#TopCategoryTwo)
|
||||
[Here, we correctly jump to T1-S2](#TopCategoryOne#SubCategoryTwo)
|
||||
[Here, however, we incorrectly land at T1-S2](#TopCategoryTwo#SubCategoryTwo)
|
||||
[T2-S3 works, likely because T1-S3 doesn't exist](#TopCategoryTwo#SubCategoryThree)
|
||||
|
||||
# TopCategoryOne
|
||||
## SubCategoryOne
|
||||
## SubCategoryTwo
|
||||
|
||||
|
||||
# TopCategoryTwo
|
||||
## SubCategoryOne
|
||||
## SubCategoryTwo
|
||||
## SubCategoryThree
|
||||
|
||||
|
||||
Execute (Set syntax markdown):
|
||||
call SetSyntax('markdown')
|
||||
file issue1356.md
|
||||
Log 'Initial file:' . resolve(expand('%:p'))
|
||||
|
||||
|
||||
Do (Jump1):
|
||||
1G
|
||||
\<Cr>
|
||||
A--Link1\<Esc>
|
||||
|
||||
|
||||
Expect(Link1):
|
||||
[this](#TopCategoryOne)
|
||||
[that](#TopCategoryTwo)
|
||||
[Here, we correctly jump to T1-S2](#TopCategoryOne#SubCategoryTwo)
|
||||
[Here, however, we incorrectly land at T1-S2](#TopCategoryTwo#SubCategoryTwo)
|
||||
[T2-S3 works, likely because T1-S3 doesn't exist](#TopCategoryTwo#SubCategoryThree)
|
||||
|
||||
# TopCategoryOne--Link1
|
||||
## SubCategoryOne
|
||||
## SubCategoryTwo
|
||||
|
||||
|
||||
# TopCategoryTwo
|
||||
## SubCategoryOne
|
||||
## SubCategoryTwo
|
||||
## SubCategoryThree
|
||||
|
||||
|
||||
Do (Jump2):
|
||||
2G
|
||||
\<Cr>
|
||||
A--Link2\<Esc>
|
||||
|
||||
|
||||
Expect (Link2):
|
||||
[this](#TopCategoryOne)
|
||||
[that](#TopCategoryTwo)
|
||||
[Here, we correctly jump to T1-S2](#TopCategoryOne#SubCategoryTwo)
|
||||
[Here, however, we incorrectly land at T1-S2](#TopCategoryTwo#SubCategoryTwo)
|
||||
[T2-S3 works, likely because T1-S3 doesn't exist](#TopCategoryTwo#SubCategoryThree)
|
||||
|
||||
# TopCategoryOne
|
||||
## SubCategoryOne
|
||||
## SubCategoryTwo
|
||||
|
||||
|
||||
# TopCategoryTwo--Link2
|
||||
## SubCategoryOne
|
||||
## SubCategoryTwo
|
||||
## SubCategoryThree
|
||||
|
||||
|
||||
Do (Jump3):
|
||||
3G
|
||||
\<Cr>
|
||||
A--Link3\<Esc>
|
||||
|
||||
|
||||
Expect (Link3):
|
||||
[this](#TopCategoryOne)
|
||||
[that](#TopCategoryTwo)
|
||||
[Here, we correctly jump to T1-S2](#TopCategoryOne#SubCategoryTwo)
|
||||
[Here, however, we incorrectly land at T1-S2](#TopCategoryTwo#SubCategoryTwo)
|
||||
[T2-S3 works, likely because T1-S3 doesn't exist](#TopCategoryTwo#SubCategoryThree)
|
||||
|
||||
# TopCategoryOne
|
||||
## SubCategoryOne
|
||||
## SubCategoryTwo--Link3
|
||||
|
||||
|
||||
# TopCategoryTwo
|
||||
## SubCategoryOne
|
||||
## SubCategoryTwo
|
||||
## SubCategoryThree
|
||||
|
||||
|
||||
Do (Jump4):
|
||||
4G
|
||||
\<Cr>
|
||||
A--Link4\<Esc>
|
||||
|
||||
|
||||
Expect (Link4):
|
||||
[this](#TopCategoryOne)
|
||||
[that](#TopCategoryTwo)
|
||||
[Here, we correctly jump to T1-S2](#TopCategoryOne#SubCategoryTwo)
|
||||
[Here, however, we incorrectly land at T1-S2](#TopCategoryTwo#SubCategoryTwo)
|
||||
[T2-S3 works, likely because T1-S3 doesn't exist](#TopCategoryTwo#SubCategoryThree)
|
||||
|
||||
# TopCategoryOne
|
||||
## SubCategoryOne
|
||||
## SubCategoryTwo
|
||||
|
||||
|
||||
# TopCategoryTwo
|
||||
## SubCategoryOne
|
||||
## SubCategoryTwo--Link4
|
||||
## SubCategoryThree
|
||||
|
||||
|
||||
Do (Jump5):
|
||||
5G
|
||||
\<Cr>
|
||||
A--Link5\<Esc>
|
||||
|
||||
|
||||
Expect (Link5):
|
||||
[this](#TopCategoryOne)
|
||||
[that](#TopCategoryTwo)
|
||||
[Here, we correctly jump to T1-S2](#TopCategoryOne#SubCategoryTwo)
|
||||
[Here, however, we incorrectly land at T1-S2](#TopCategoryTwo#SubCategoryTwo)
|
||||
[T2-S3 works, likely because T1-S3 doesn't exist](#TopCategoryTwo#SubCategoryThree)
|
||||
|
||||
# TopCategoryOne
|
||||
## SubCategoryOne
|
||||
## SubCategoryTwo
|
||||
|
||||
|
||||
# TopCategoryTwo
|
||||
## SubCategoryOne
|
||||
## SubCategoryTwo
|
||||
## SubCategoryThree--Link5
|
||||
Reference in New Issue
Block a user