From eaacdd059ed6ceb64d6f17faf9d2576fb510e501 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 27 May 2023 21:44:20 +0800 Subject: [PATCH] vim-patch:9.0.1582: :stopinsert may not work in a popup close handler Problem: :stopinsert may not work in a popup close handler. (Ben Jackson) Solution: Restore stop_insert_mode when appropriate. (closes vim/vim#12452, closes vim/vim#12434) https://github.com/vim/vim/commit/a40c0bcc83c32da02869f59b10538d6327df61c5 (cherry picked from commit a9d6bc70823b4f11572928fd7e5166c9edf0a26c) --- src/nvim/autocmd.c | 4 +++- test/old/testdir/test_quickfix.vim | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index 726344a42b..9cb9bf0eee 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -1497,11 +1497,13 @@ void aucmd_restbuf(aco_save_T *aco) } } win_found: + ; + const bool save_stop_insert_mode = stop_insert_mode; // May need to stop Insert mode if we were in a prompt buffer. leaving_window(curwin); // Do not stop Insert mode when already in Insert mode before. if (aco->save_State & MODE_INSERT) { - stop_insert_mode = false; + stop_insert_mode = save_stop_insert_mode; } // Remove the window. win_remove(curwin, NULL); diff --git a/test/old/testdir/test_quickfix.vim b/test/old/testdir/test_quickfix.vim index fedc486e62..1de0bf9a32 100644 --- a/test/old/testdir/test_quickfix.vim +++ b/test/old/testdir/test_quickfix.vim @@ -6292,5 +6292,28 @@ func Test_setqflist_cb_arg() call setqflist([], 'f') endfunc +" Test that setqflist() should not prevent :stopinsert from working +func Test_setqflist_stopinsert() + new + call setqflist([], 'f') + copen + cclose + func StopInsert() + stopinsert + call setqflist([{'text': 'foo'}]) + return '' + endfunc + + call setline(1, 'abc') + call cursor(1, 1) + call feedkeys("i\=StopInsert()\$", 'tnix') + call assert_equal('foo', getqflist()[0].text) + call assert_equal([0, 1, 3, 0, v:maxcol], getcurpos()) + call assert_equal(['abc'], getline(1, '$')) + + delfunc StopInsert + call setqflist([], 'f') + bwipe! +endfunc " vim: shiftwidth=2 sts=2 expandtab