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:
Junegunn Choi
2026-08-26 22:47:46 +09:00
parent 4ae5a659f8
commit cb6ea5e06f
+8 -5
View File
@@ -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