Fix: VimwikiGoBackLink does not go back to links on the same page #691
This commit is contained in:
		@@ -336,12 +336,9 @@ function! vimwiki#base#open_link(cmd, link, ...)
 | 
			
		||||
 | 
			
		||||
  let is_wiki_link = s:is_wiki_link(link_infos)
 | 
			
		||||
 | 
			
		||||
  let update_prev_link = is_wiki_link &&
 | 
			
		||||
        \ !vimwiki#path#is_equal(link_infos.filename, vimwiki#path#current_wiki_file())
 | 
			
		||||
 | 
			
		||||
  let vimwiki_prev_link = []
 | 
			
		||||
  " update previous link for wiki pages
 | 
			
		||||
  if update_prev_link
 | 
			
		||||
  if is_wiki_link
 | 
			
		||||
    if a:0
 | 
			
		||||
      let vimwiki_prev_link = [a:1, []]
 | 
			
		||||
    elseif &ft ==# 'vimwiki'
 | 
			
		||||
@@ -352,7 +349,7 @@ function! vimwiki#base#open_link(cmd, link, ...)
 | 
			
		||||
  " open/edit
 | 
			
		||||
  if is_wiki_link
 | 
			
		||||
    call vimwiki#base#edit_file(a:cmd, link_infos.filename, link_infos.anchor,
 | 
			
		||||
          \ vimwiki_prev_link, update_prev_link)
 | 
			
		||||
          \ vimwiki_prev_link, is_wiki_link)
 | 
			
		||||
  else
 | 
			
		||||
    call vimwiki#base#system_open_link(link_infos.filename)
 | 
			
		||||
  endif
 | 
			
		||||
@@ -861,7 +858,9 @@ function! vimwiki#base#edit_file(command, filename, anchor, ...)
 | 
			
		||||
  " a:1 -- previous vimwiki link to save
 | 
			
		||||
  " a:2 -- should we update previous link
 | 
			
		||||
  if a:0 && a:2 && len(a:1) > 0
 | 
			
		||||
    call vimwiki#vars#set_bufferlocal('prev_link', a:1)
 | 
			
		||||
    let prev_links = vimwiki#vars#get_bufferlocal('prev_links')
 | 
			
		||||
    call insert(prev_links, a:1)
 | 
			
		||||
    call vimwiki#vars#set_bufferlocal('prev_links', prev_links)
 | 
			
		||||
  endif
 | 
			
		||||
endfunction
 | 
			
		||||
 | 
			
		||||
@@ -1040,7 +1039,7 @@ function! s:get_wiki_buffers()
 | 
			
		||||
      " this may find buffers that are not part of the current wiki, but that
 | 
			
		||||
      " doesn't hurt
 | 
			
		||||
      if bname =~# vimwiki#vars#get_wikilocal('ext')."$"
 | 
			
		||||
        let bitem = [bname, vimwiki#vars#get_bufferlocal('prev_link', bcount)]
 | 
			
		||||
        let bitem = [bname, vimwiki#vars#get_bufferlocal('prev_links', bcount)]
 | 
			
		||||
        call add(blist, bitem)
 | 
			
		||||
      endif
 | 
			
		||||
    endif
 | 
			
		||||
@@ -1053,7 +1052,7 @@ endfunction
 | 
			
		||||
function! s:open_wiki_buffer(item)
 | 
			
		||||
  call vimwiki#base#edit_file(':e', a:item[0], '')
 | 
			
		||||
  if !empty(a:item[1])
 | 
			
		||||
    call vimwiki#vars#set_bufferlocal('prev_link', a:item[1], a:item[0])
 | 
			
		||||
    call vimwiki#vars#set_bufferlocal('prev_links', a:item[1], a:item[0])
 | 
			
		||||
  endif
 | 
			
		||||
endfunction
 | 
			
		||||
 | 
			
		||||
@@ -1353,7 +1352,15 @@ endfunction
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function! vimwiki#base#go_back_link()
 | 
			
		||||
  let prev_link = vimwiki#vars#get_bufferlocal('prev_link')
 | 
			
		||||
  " try pop previous link from buffer list
 | 
			
		||||
  let prev_links = vimwiki#vars#get_bufferlocal('prev_links')
 | 
			
		||||
  if !empty(prev_links)
 | 
			
		||||
    let prev_link = remove(prev_links, 0)
 | 
			
		||||
    call vimwiki#vars#set_bufferlocal('prev_links', prev_links)
 | 
			
		||||
  else
 | 
			
		||||
    let prev_link = []
 | 
			
		||||
  endif
 | 
			
		||||
 | 
			
		||||
  if !empty(prev_link)
 | 
			
		||||
    " go back to saved wiki link
 | 
			
		||||
    call vimwiki#base#edit_file(':e ', prev_link[0], '')
 | 
			
		||||
@@ -1485,7 +1492,7 @@ function! vimwiki#base#rename_link()
 | 
			
		||||
 | 
			
		||||
  let &buftype="nofile"
 | 
			
		||||
 | 
			
		||||
  let cur_buffer = [expand('%:p'), vimwiki#vars#get_bufferlocal('prev_link')]
 | 
			
		||||
  let cur_buffer = [expand('%:p'), vimwiki#vars#get_bufferlocal('prev_links')]
 | 
			
		||||
 | 
			
		||||
  let blist = s:get_wiki_buffers()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -905,8 +905,8 @@ function! vimwiki#vars#get_bufferlocal(key, ...)
 | 
			
		||||
  elseif a:key ==# 'existing_wikidirs'
 | 
			
		||||
    call setbufvar(buffer, 'vimwiki_existing_wikidirs',
 | 
			
		||||
        \ vimwiki#base#get_wiki_directories(vimwiki#vars#get_bufferlocal('wiki_nr')))
 | 
			
		||||
  elseif a:key ==# 'prev_link'
 | 
			
		||||
    call setbufvar(buffer, 'vimwiki_prev_link', [])
 | 
			
		||||
  elseif a:key ==# 'prev_links'
 | 
			
		||||
    call setbufvar(buffer, 'vimwiki_prev_links', [])
 | 
			
		||||
  elseif a:key ==# 'markdown_refs'
 | 
			
		||||
    call setbufvar(buffer, 'vimwiki_markdown_refs', vimwiki#markdown_base#scan_reflinks())
 | 
			
		||||
  else
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user