summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2018-08-20 15:31:41 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2018-08-20 15:31:41 +0900
commit8c6fcee3caef11eff4875e98d98debca7cef8df2 (patch)
tree86601e9f912c9c882c4c7a952730b1f335b6cace /plugin
parent13803d0dbbe3b189af6d2ed6af983c1143a6b0e9 (diff)
[vim] Fix directory switching around sink function
Close #1356 Related: - #612 - https://github.com/junegunn/fzf.vim/issues/308
Diffstat (limited to 'plugin')
-rw-r--r--plugin/fzf.vim36
1 files changed, 21 insertions, 15 deletions
diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index c32e3b0a..5eca120e 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -357,7 +357,7 @@ try
throw v:exception
endtry
- if has('nvim') && !has_key(dict, 'dir')
+ if !has_key(dict, 'dir')
let dict.dir = s:fzf_getcwd()
endif
if has('win32unix') && has_key(dict, 'dir')
@@ -477,7 +477,25 @@ function! s:dopopd()
if !exists('w:fzf_pushd')
return
endif
- execute w:fzf_pushd.command s:escape(w:fzf_pushd.origin)
+
+ " FIXME: We temporarily change the working directory to 'dir' entry
+ " of options dictionary (set to the current working directory if not given)
+ " before running fzf.
+ "
+ " e.g. call fzf#run({'dir': '/tmp', 'source': 'ls', 'sink': 'e'})
+ "
+ " After processing the sink function, we have to restore the current working
+ " directory. But doing so may not be desirable if the function changed the
+ " working directory on purpose.
+ "
+ " So how can we tell if we should do it or not? A simple heuristic we use
+ " here is that we change directory only if the current working directory
+ " matches 'dir' entry. However, it is possible that the sink function did
+ " change the directory to 'dir'. In that case, the user will have an
+ " unexpected result.
+ if s:fzf_getcwd() ==# w:fzf_pushd.dir
+ execute w:fzf_pushd.command s:escape(w:fzf_pushd.origin)
+ endif
unlet w:fzf_pushd
endfunction
@@ -724,19 +742,7 @@ function! s:collect(temps) abort
endfunction
function! s:callback(dict, lines) abort
- " Since anything can be done in the sink function, there is no telling that
- " the change of the working directory was made by &autochdir setting.
- "
- " We use the following heuristic to determine whether to restore CWD:
- " - Always restore the current directory when &autochdir is disabled.
- " FIXME This makes it impossible to change directory from inside the sink
- " function when &autochdir is not used.
- " - In case of an error or an interrupt, a:lines will be empty.
- " And it will be an array of a single empty string when fzf was finished
- " without a match. In these cases, we presume that the change of the
- " directory is not expected and should be undone.
- let popd = has_key(a:dict, 'pushd') &&
- \ (!&autochdir || (empty(a:lines) || len(a:lines) == 1 && empty(a:lines[0])))
+ let popd = has_key(a:dict, 'pushd')
if popd
let w:fzf_pushd = a:dict.pushd
endif