summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorichizok <gclient.gaap@gmail.com>2020-05-15 15:25:33 +0900
committerGitHub <noreply@github.com>2020-05-15 15:25:33 +0900
commitd631c76e8d2dd18876a09d2c0919ece1a42a8721 (patch)
tree8e44f2bf54d020435da4000b1cfb619e0e7bb8f4 /plugin
parente6d33f77da8cc36786c814f499f6cb3405e8c4c1 (diff)
[vim] Don't start extra process when opening popup (#2000)
Fix #2038
Diffstat (limited to 'plugin')
-rw-r--r--plugin/fzf.vim32
1 files changed, 21 insertions, 11 deletions
diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index a84dcab7..c2889487 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -648,6 +648,7 @@ function! s:split(dict)
\ 'left': ['vertical topleft', 'vertical resize', &columns],
\ 'right': ['vertical botright', 'vertical resize', &columns] }
let ppos = s:getpos()
+ let is_popup = 0
try
if s:present(a:dict, 'window')
if type(a:dict.window) == type({})
@@ -655,6 +656,7 @@ function! s:split(dict)
throw 'Vim 8.2.191 or later is required for pop-up window'
end
call s:popup(a:dict.window)
+ let is_popup = 1
else
execute 'keepalt' a:dict.window
endif
@@ -672,11 +674,11 @@ function! s:split(dict)
endif
execute cmd sz.'new'
execute resz sz
- return [ppos, {}]
+ return [ppos, {}, is_popup]
endif
endfor
endif
- return [ppos, { '&l:wfw': &l:wfw, '&l:wfh': &l:wfh }]
+ return [ppos, { '&l:wfw': &l:wfw, '&l:wfh': &l:wfh }, is_popup]
finally
setlocal winfixwidth winfixheight
endtry
@@ -685,7 +687,7 @@ endfunction
function! s:execute_term(dict, command, temps) abort
let winrest = winrestcmd()
let pbuf = bufnr('')
- let [ppos, winopts] = s:split(a:dict)
+ let [ppos, winopts, is_popup] = s:split(a:dict)
call s:use_sh()
let b:fzf = a:dict
let fzf = { 'buf': bufnr(''), 'pbuf': pbuf, 'ppos': ppos, 'dict': a:dict, 'temps': a:temps,
@@ -752,8 +754,17 @@ function! s:execute_term(dict, command, temps) abort
if !len(&bufhidden)
setlocal bufhidden=hide
endif
- let fzf.buf = term_start([&shell, &shellcmdflag, command], {'curwin': 1, 'exit_cb': function(fzf.on_exit)})
- if !has('patch-8.0.1261') && !has('nvim') && !s:is_win
+ let term_opts = {'exit_cb': function(fzf.on_exit)}
+ if is_popup
+ let term_opts.hidden = 1
+ else
+ let term_opts.curwin = 1
+ endif
+ let fzf.buf = term_start([&shell, &shellcmdflag, command], term_opts)
+ if is_popup && exists('#TerminalWinOpen')
+ doautocmd <nomodeline> TerminalWinOpen
+ endif
+ if !has('patch-8.0.1261') && !s:is_win
call term_wait(fzf.buf, 20)
endif
endif
@@ -824,23 +835,22 @@ if has('nvim')
else
function! s:create_popup(hl, opts) abort
let is_frame = has_key(a:opts, 'border')
- let buf = is_frame ? '' : term_start(&shell, #{hidden: 1, term_finish: 'close'})
- let id = popup_create(buf, #{
+ let s:popup_create = {buf -> popup_create(buf, #{
\ line: a:opts.row,
\ col: a:opts.col,
\ minwidth: a:opts.width,
\ minheight: a:opts.height,
\ zindex: 50 - is_frame,
- \ })
-
+ \ })}
if is_frame
+ let id = s:popup_create('')
call setwinvar(id, '&wincolor', a:hl)
call setbufline(winbufnr(id), 1, a:opts.border)
execute 'autocmd BufWipeout * ++once call popup_close('..id..')'
+ return winbufnr(id)
else
- execute 'autocmd BufWipeout * ++once call term_sendkeys('..buf..', "exit\<CR>")'
+ autocmd TerminalOpen * ++once call s:popup_create(str2nr(expand('<abuf>')))
endif
- return winbufnr(id)
endfunction
endif