Feature: VimwikiGoto completion works with only part of filename
Problem: Could not complete when the user argument was not the begining of the filepath Solution: use custom smartcase filter and customlist instead of custom
This commit is contained in:
		@@ -356,7 +356,8 @@ function! vimwiki#base#open_link(cmd, link, ...)
 | 
				
			|||||||
endfunction
 | 
					endfunction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function! vimwiki#base#get_globlinks_escaped() abort
 | 
					function! vimwiki#base#get_globlinks_escaped(...) abort
 | 
				
			||||||
 | 
					  let s_arg_lead = a:0 > 0 ? a:1 : ""
 | 
				
			||||||
  " only get links from the current dir
 | 
					  " only get links from the current dir
 | 
				
			||||||
  " change to the directory of the current file
 | 
					  " change to the directory of the current file
 | 
				
			||||||
  let orig_pwd = getcwd()
 | 
					  let orig_pwd = getcwd()
 | 
				
			||||||
@@ -369,12 +370,14 @@ function! vimwiki#base#get_globlinks_escaped() abort
 | 
				
			|||||||
  exe 'lcd! '.orig_pwd
 | 
					  exe 'lcd! '.orig_pwd
 | 
				
			||||||
  " convert to a List
 | 
					  " convert to a List
 | 
				
			||||||
  let lst = split(globlinks, '\n')
 | 
					  let lst = split(globlinks, '\n')
 | 
				
			||||||
 | 
					  " Filter files whose path matches the  user's argument leader
 | 
				
			||||||
 | 
					  " " use smart case matching
 | 
				
			||||||
 | 
					  let r_arg = substitute(s_arg_lead, '\u', '[\0\l\0]', 'g')
 | 
				
			||||||
 | 
					  call filter(lst, '-1 != match(v:val, r_arg)')
 | 
				
			||||||
  " Apply fnameescape() to each item
 | 
					  " Apply fnameescape() to each item
 | 
				
			||||||
  call map(lst, 'fnameescape(v:val)')
 | 
					  call map(lst, 'fnameescape(v:val)')
 | 
				
			||||||
  " Convert back to newline-separated list
 | 
					  " Return list (for customlist completion)
 | 
				
			||||||
  let globlinks = join(lst, "\n")
 | 
					  return lst
 | 
				
			||||||
  " return all escaped links as a single newline-separated string
 | 
					 | 
				
			||||||
  return globlinks
 | 
					 | 
				
			||||||
endfunction
 | 
					endfunction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -2279,9 +2282,7 @@ endfunction
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function! vimwiki#base#complete_links_escaped(ArgLead, CmdLine, CursorPos) abort
 | 
					function! vimwiki#base#complete_links_escaped(ArgLead, CmdLine, CursorPos) abort
 | 
				
			||||||
  " We can safely ignore args if we use -custom=complete option, Vim engine
 | 
					  return vimwiki#base#get_globlinks_escaped(a:ArgLead)
 | 
				
			||||||
  " will do the job of filtering.
 | 
					 | 
				
			||||||
  return vimwiki#base#get_globlinks_escaped()
 | 
					 | 
				
			||||||
endfunction
 | 
					endfunction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -261,7 +261,7 @@ command! -buffer -nargs=0 VWB call vimwiki#base#backlinks()
 | 
				
			|||||||
command! -buffer -nargs=* VimwikiSearch call vimwiki#base#search(<q-args>)
 | 
					command! -buffer -nargs=* VimwikiSearch call vimwiki#base#search(<q-args>)
 | 
				
			||||||
command! -buffer -nargs=* VWS call vimwiki#base#search(<q-args>)
 | 
					command! -buffer -nargs=* VWS call vimwiki#base#search(<q-args>)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
command! -buffer -nargs=* -complete=custom,vimwiki#base#complete_links_escaped
 | 
					command! -buffer -nargs=* -complete=customlist,vimwiki#base#complete_links_escaped
 | 
				
			||||||
      \ VimwikiGoto call vimwiki#base#goto(<f-args>)
 | 
					      \ VimwikiGoto call vimwiki#base#goto(<f-args>)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
command! -buffer VimwikiCheckLinks call vimwiki#base#check_links()
 | 
					command! -buffer VimwikiCheckLinks call vimwiki#base#check_links()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,13 +17,48 @@ Do (VimwikiGoto <CR> buzz_bozz && Assert):
 | 
				
			|||||||
  buzz_bozz\<CR>
 | 
					  buzz_bozz\<CR>
 | 
				
			||||||
  :AssertEqual $HOME . '/testmarkdown/buzz_bozz.md', expand('%')\<CR>
 | 
					  :AssertEqual $HOME . '/testmarkdown/buzz_bozz.md', expand('%')\<CR>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
Execute (:VimwikiGoto + Completion):
 | 
					Execute (:VimwikiGoto + Completion):
 | 
				
			||||||
  VimwikiIndex 2
 | 
					  VimwikiIndex 2
 | 
				
			||||||
  AssertEqual $HOME . '/testmarkdown/index.md', expand('%')
 | 
					  AssertEqual $HOME . '/testmarkdown/index.md', expand('%')
 | 
				
			||||||
  let s_complete=vimwiki#base#get_globlinks_escaped()
 | 
					  let s_complete=string(vimwiki#base#get_globlinks_escaped())
 | 
				
			||||||
  Assert -1 != stridx(s_complete, 'buzz_bozz')
 | 
					  Assert -1 != stridx(s_complete, 'buzz_bozz')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Execute (Create dir1/dir2/test_goto_file.md):
 | 
				
			||||||
 | 
					  call system("mkdir $HOME/testmarkdown/dir1")
 | 
				
			||||||
 | 
					  call system("mkdir $HOME/testmarkdown/dir1/dir2")
 | 
				
			||||||
 | 
					  edit $HOME/testmarkdown/dir1/dir2/test_goto_file.md
 | 
				
			||||||
 | 
					  call WriteMe()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Execute (:VimwikiGoto + Completion in directory):
 | 
				
			||||||
 | 
					  " Return to base
 | 
				
			||||||
 | 
					  VimwikiIndex 2
 | 
				
			||||||
 | 
					  AssertEqual $HOME . '/testmarkdown/index.md', expand('%')
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  " Complete without argment
 | 
				
			||||||
 | 
					  let s_complete1=string(vimwiki#base#get_globlinks_escaped())
 | 
				
			||||||
 | 
					  Assert -1 != stridx(s_complete1, 'test_goto_file')
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  " Complete with file argument
 | 
				
			||||||
 | 
					  let s_complete2=string(vimwiki#base#get_globlinks_escaped('test_goto_file'))
 | 
				
			||||||
 | 
					  Assert -1 != stridx(s_complete2, 'test_goto_file')
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  " Complete with start of file argument
 | 
				
			||||||
 | 
					  let s_complete3=string(vimwiki#base#get_globlinks_escaped('test_got'))
 | 
				
			||||||
 | 
					  Assert -1 != stridx(s_complete3, 'test_goto_file')
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  " Complete with (nested) dir2 argument
 | 
				
			||||||
 | 
					  let s_complete4=string(vimwiki#base#get_globlinks_escaped('dir2'))
 | 
				
			||||||
 | 
					  Assert -1 != stridx(s_complete4, 'test_goto_file')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  " Complete with bad argument
 | 
				
			||||||
 | 
					  let l_complete5=vimwiki#base#get_globlinks_escaped('this_string_is_nowhere')
 | 
				
			||||||
 | 
					  let s_complete5=string(l_complete5)
 | 
				
			||||||
 | 
					  Assert -1 == stridx(s_complete5, 'test_goto_file')
 | 
				
			||||||
 | 
					  AssertEqual 0, len(l_complete5)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Execute (Clean):
 | 
				
			||||||
 | 
					  Log "End: Clean"
 | 
				
			||||||
 | 
					  call system("rm $HOME/testmarkdown/dir1")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Include: vader_includes/vader_teardown.vader
 | 
					Include: vader_includes/vader_teardown.vader
 | 
				
			||||||
# vim: sw=2 ft=conf foldmethod=indent foldlevel=30 foldignore=
 | 
					# vim: sw=2 ft=conf foldmethod=indent foldlevel=30 foldignore=
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user