mirror of
https://github.com/junegunn/fzf.vim.git
synced 2026-08-31 11:56:56 +08:00
Prefer a relative entry over tilde expansion in s:in_dir
Only :History reports a path as '~/...', but every command went through the same branch, so an entry under a directory literally named '~' resolved to the home directory and Show opened the wrong file or nothing. Resolve against the run directory first and fall back to the home reading.
This commit is contained in:
@@ -637,14 +637,17 @@ endfunction
|
||||
" fzf#run restores the working directory while fzf runs and only re-applies
|
||||
" 'dir' for the sink, so a relative entry has to be resolved here
|
||||
function! s:in_dir(dir, path) abort
|
||||
" filereadable does not expand a leading tilde, which :History reports
|
||||
if a:path =~# '^\~'
|
||||
return fnamemodify(a:path, ':p')
|
||||
endif
|
||||
if empty(a:dir) || a:path =~# '^/' || a:path =~# '^\a:[\\/]'
|
||||
return a:path
|
||||
endif
|
||||
return fnamemodify(expand(escape(a:dir, '[]*?{}')), ':p').a:path
|
||||
let path = fnamemodify(expand(escape(a:dir, '[]*?{}')), ':p').a:path
|
||||
" :History reports a path under the home directory as '~/...', which
|
||||
" filereadable does not expand. Other commands can emit a relative path
|
||||
" under a directory named '~', so prefer that reading when it exists
|
||||
if a:path =~# '^\~' && !filereadable(path)
|
||||
return fnamemodify(a:path, ':p')
|
||||
endif
|
||||
return path
|
||||
endfunction
|
||||
|
||||
" Shows the entry without closing fzf. The callback can fire while the fzf
|
||||
|
||||
Reference in New Issue
Block a user