Skip to content

Commit

Permalink
vim-patch:8.2.1781: writing to prompt buffer interferes with insert mode
Browse files Browse the repository at this point in the history
Problem:    Writing to prompt buffer interferes with insert mode.
Solution:   Use win_enter() instead of just setting "curwin". (Ben Jackson,
            closes vim/vim#7035)
vim/vim@4537bcc

Patch v8.2.1783 has fixes.
  • Loading branch information
seandewar committed Nov 8, 2021
1 parent 96daf4f commit 4a67257
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/nvim/autocmd.c
Expand Up @@ -1201,7 +1201,7 @@ void aucmd_restbuf(aco_save_T *aco)

win_T *const save_curwin = win_find_by_handle(aco->save_curwin_handle);
if (save_curwin != NULL) {
curwin = save_curwin;
win_enter(save_curwin, true);
} else {
// Hmm, original window disappeared. Just use the first one.
curwin = firstwin;
Expand Down
34 changes: 34 additions & 0 deletions src/nvim/testdir/test_prompt_buffer.vim
Expand Up @@ -188,4 +188,38 @@ func Test_prompt_buffer_getbufinfo()
%bwipe!
endfunc

function! Test_prompt_while_writing_to_hidden_buffer()
throw 'skipped: TODO'
call CanTestPromptBuffer()
CheckUnix

" Make a job continuously write to a hidden buffer, check that the prompt
" buffer is not affected.
let scriptName = 'XpromptscriptHiddenBuf'
let script =<< trim END
set buftype=prompt
call prompt_setprompt( bufnr(), 'cmd:' )
let job = job_start(['/bin/sh', '-c',
\ 'while true;
\ do echo line;
\ sleep 0.1;
\ done'], #{out_io: 'buffer', out_name: ''})
startinsert
END
eval script->writefile(scriptName)

let buf = RunVimInTerminal('-S ' .. scriptName, {})
call WaitForAssert({-> assert_equal('cmd:', term_getline(buf, 1))})

call term_sendkeys(buf, 'test')
call WaitForAssert({-> assert_equal('cmd:test', term_getline(buf, 1))})
call term_sendkeys(buf, 'test')
call WaitForAssert({-> assert_equal('cmd:testtest', term_getline(buf, 1))})
call term_sendkeys(buf, 'test')
call WaitForAssert({-> assert_equal('cmd:testtesttest', term_getline(buf, 1))})

call StopVimInTerminal(buf)
call delete(scriptName)
endfunc

" vim: shiftwidth=2 sts=2 expandtab

0 comments on commit 4a67257

Please sign in to comment.