diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2023-08-16 16:17:31 +0100 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2024-01-23 22:35:05 +0100 |
commit | 43b395ec2e7d24a067d7cb00109818b64da144a5 (patch) | |
tree | fd8dfe4d22990fb00eab5d341ff2eaf1987b4c76 /src/testdir/test_cmdwin.vim | |
parent | 988f74311c26ea9917e84fbae608de226dba7e5f (diff) |
patch 9.1.0048: Abort opening cmdwin if autocmds screw things upv9.1.0048
Problem: Autocmds triggered from opening the cmdwin (in win_split and
do_ecmd) can cause issues such as E199, as the current checks
are insufficient.
Solution: Commands executed from the cmdwin apply to the old curwin/buf,
so they should be kept in a "suspended" state; abort if
they've changed. Also abort if cmdwin/buf was tampered with,
and check that curwin is correct. Try to clean up the cmdwin
buffer (only if hidden and non-current to simplify things; the
same approach is used when closing cmdwin normally), and add a
beep. (Sean Dewar)
It'd be nice to also check that curwin was *really* created by win_split, as
autocommands can change curwin before it returns (so it can't be assumed to be
that of the split); for now, this means that the cmdwin may not be the botwin in
that case, which is probably OK.
closes: #12819
Signed-off-by: Sean Dewar <seandewar@users.noreply.github.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/testdir/test_cmdwin.vim')
-rw-r--r-- | src/testdir/test_cmdwin.vim | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/src/testdir/test_cmdwin.vim b/src/testdir/test_cmdwin.vim index 0c7d29710f..494c8065f2 100644 --- a/src/testdir/test_cmdwin.vim +++ b/src/testdir/test_cmdwin.vim @@ -188,7 +188,7 @@ func Test_cmdwin_tabpage() tabclose! endfunc -func Test_cmdwin_interrupted() +func Test_cmdwin_interrupted_more_prompt() CheckScreendump " aborting the :smile output caused the cmdline window to use the current @@ -498,9 +498,75 @@ func Test_cmdwin_temp_curwin() call feedkeys("q::call CheckCmdWin()\<CR>:call win_execute(win_getid(winnr('#')), 'call CheckOtherWin()')\<CR>:q<CR>", 'ntx') + %bwipe! delfunc CheckWraps delfunc CheckCmdWin delfunc CheckOtherWin endfunc +func Test_cmdwin_interrupted() + func CheckInterrupted() + call feedkeys("q::call assert_equal('', getcmdwintype())\<CR>:call assert_equal('', getcmdtype())\<CR>:q<CR>", 'ntx') + endfunc + + augroup CmdWin + + " While opening the cmdwin's split: + " Close the cmdwin's window. + au WinEnter * ++once quit + call CheckInterrupted() + + " Close the old window. + au WinEnter * ++once execute winnr('#') 'quit' + call CheckInterrupted() + + " Switch back to the old window. + au WinEnter * ++once wincmd p + call CheckInterrupted() + + " Change the old window's buffer. + au WinEnter * ++once call win_execute(win_getid(winnr('#')), 'enew') + call CheckInterrupted() + + " Using BufLeave autocmds as cmdwin restrictions do not apply to them when + " fired from opening the cmdwin... + " After opening the cmdwin's split, while creating the cmdwin's buffer: + " Delete the cmdwin's buffer. + au BufLeave * ++once bwipe + call CheckInterrupted() + + " Close the cmdwin's window. + au BufLeave * ++once quit + call CheckInterrupted() + + " Close the old window. + au BufLeave * ++once execute winnr('#') 'quit' + call CheckInterrupted() + + " Switch to a different window. + au BufLeave * ++once split + call CheckInterrupted() + + " Change the old window's buffer. + au BufLeave * ++once call win_execute(win_getid(winnr('#')), 'enew') + call CheckInterrupted() + + " However, changing the current buffer is OK and does not interrupt. + au BufLeave * ++once edit other + call feedkeys("q::let t=getcmdwintype()\<CR>:let b=bufnr()\<CR>:clo<CR>", 'ntx') + call assert_equal(':', t) + call assert_equal(1, bufloaded('other')) + call assert_notequal(b, bufnr('other')) + + augroup END + + " No autocmds should remain, but clear the augroup to be sure. + augroup CmdWin + au! + augroup END + + %bwipe! + delfunc CheckInterrupted +endfunc + " vim: shiftwidth=2 sts=2 expandtab |