Handle race condition closing job stdin

This race condition is there for any key press, but it's greatly
exaggerated by Vim's default one second timeout on Escape.  This delay
also disqualifies Escape as the official interface to this feature, but
leave it as a DWIM alternative to CTRL-D for now.

Closes https://github.com/tpope/vim-fugitive/issues/1722
This commit is contained in:
Tim Pope
2021-04-01 20:01:54 -04:00
parent 1d91517cdb
commit 5a54ea4333

View File

@@ -2566,6 +2566,19 @@ function! s:RunSend(job, str) abort
endtry endtry
endfunction endfunction
function! s:RunCloseIn(job) abort
try
if type(a:job) ==# type(0)
call chanclose(a:job, 'stdin')
else
call ch_close_in(a:job)
endif
return 1
catch /^Vim\%((\a\+)\)\=:E90[06]:/
return 0
endtry
endfunction
function! s:RunEcho(tmp) abort function! s:RunEcho(tmp) abort
if !has_key(a:tmp, 'echo') if !has_key(a:tmp, 'echo')
return return
@@ -2605,12 +2618,7 @@ function! s:RunWait(state, tmp, job, ...) abort
let c = type(c) == type(0) ? nr2char(c) : c let c = type(c) == type(0) ? nr2char(c) : c
if c ==# "\<C-D>" || c ==# "\<Esc>" if c ==# "\<C-D>" || c ==# "\<Esc>"
let a:state.closed_in = 1 let a:state.closed_in = 1
if type(a:job) ==# type(0) let can_pedit = s:RunCloseIn(a:job) && exists('*setbufline')
call chanclose(a:job, 'stdin')
else
call ch_close_in(a:job)
endif
let can_pedit = exists('*setbufline')
for winnr in range(1, winnr('$')) for winnr in range(1, winnr('$'))
if getwinvar(winnr, '&previewwindow') && getbufvar(winbufnr(winnr), '&modified') if getwinvar(winnr, '&previewwindow') && getbufvar(winbufnr(winnr), '&modified')
let can_pedit = 0 let can_pedit = 0