diff --git a/autoload/vimtex/complete.vim b/autoload/vimtex/complete.vim index ed8724c..703a45f 100644 --- a/autoload/vimtex/complete.vim +++ b/autoload/vimtex/complete.vim @@ -381,27 +381,14 @@ let s:img = { \} function! s:img.complete(regex) dict " {{{2 - call self.get_graphicspaths() call self.gather_candidates() - call filter(self.candidates, 'v:val =~# a:regex') - - call map(self.candidates, '{ - \ ''abbr'' : v:val, - \ ''word'' : v:val, - \ ''menu'' : '' [graphics]'', - \ }') - - if !empty(self.graphicspaths) - for l:cand in self.candidates - let l:cand.word = fnamemodify(l:cand.word, ':t') - endfor - endif + call filter(self.candidates, 'v:val.word =~# a:regex') return self.candidates endfunction -function! s:img.get_graphicspaths() dict " {{{2 +function! s:img.graphicspaths() dict " {{{2 " Get preamble text and remove comments let l:preamble = vimtex#parser#tex(b:vimtex.tex, { \ 're_stop': '\\begin{document}', @@ -409,26 +396,42 @@ function! s:img.get_graphicspaths() dict " {{{2 \}) call map(l:preamble, 'substitute(v:val, ''\\\@= 0 | continue | endif + + call add(l:added_files, l:file) + + call add(self.candidates, { + \ 'abbr': vimtex#paths#shorten_relative(l:file), + \ 'word': vimtex#paths#relative(l:file, l:path), + \ 'menu': '[graphics]', + \}) + endfor + endfor endfunction " }}}1