From 09804c2a5f1009fde29e32c5f3a6093e4684433a Mon Sep 17 00:00:00 2001 From: Tinmarino Date: Mon, 10 Jul 2023 12:19:52 -0400 Subject: [PATCH] Fix: Jump to nested anchor bugged with markdown (issue #1356) --- autoload/vimwiki/base.vim | 7 +- test/issue_1356_jump_same_header2.vader | 148 ++++++++++++++++++++++++ 2 files changed, 151 insertions(+), 4 deletions(-) create mode 100644 test/issue_1356_jump_same_header2.vader diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index d262abf..02a874a 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -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 diff --git a/test/issue_1356_jump_same_header2.vader b/test/issue_1356_jump_same_header2.vader new file mode 100644 index 0000000..50d02f5 --- /dev/null +++ b/test/issue_1356_jump_same_header2.vader @@ -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 + \ + A--Link1\ + + +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 + \ + A--Link2\ + + +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 + \ + A--Link3\ + + +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 + \ + A--Link4\ + + +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 + \ + A--Link5\ + + +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