Skip to content

Commit

Permalink
fix: properly support windows paths in #relative()
Browse files Browse the repository at this point in the history
  • Loading branch information
lervag committed Mar 31, 2024
1 parent 3275a17 commit ac0a41b
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions autoload/vimtex/paths.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ endfunction
" }}}1

function! vimtex#paths#s(path) abort " {{{1
" Use backslash on Windows
return simplify(vimtex#util#is_win()
" Handle shellescape issues and simplify path
let l:path = exists('+shellslash') && !&shellslash
\ ? tr(a:path, '/', '\')
\ : a:path)
\ : a:path

return simplify(l:path)
endfunction

" }}}1
Expand All @@ -68,20 +70,21 @@ function! vimtex#paths#relative(path, current) abort " {{{1

let l:target = simplify(substitute(a:path, '\\', '/', 'g'))
let l:common = simplify(substitute(a:current, '\\', '/', 'g'))
if l:common[-1:] ==# '/'
let l:common = l:common[:-2]
endif

if has('win32') || v:true
let l:target = substitute(l:target, '^[A-Z]:', '', '')
let l:common = substitute(l:common, '^[A-Z]:', '', '')
endif

" This only works on absolute paths
if !vimtex#paths#is_abs(l:target)
return substitute(a:path, '^\.\/', '', '')
endif

if has('win32')
let l:target = substitute(l:target, '^\a:', '', '')
let l:common = substitute(l:common, '^\a:', '', '')
endif

if l:common[-1:] ==# '/'
let l:common = l:common[:-2]
endif

let l:tries = 50
let l:result = ''
while stridx(l:target, l:common) != 0 && l:tries > 0
Expand Down

0 comments on commit ac0a41b

Please sign in to comment.