]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1582: :stopinsert may not work in a popup close handler v9.0.1582
authorzeertzjq <zeertzjq@outlook.com>
Sat, 27 May 2023 13:10:08 +0000 (14:10 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 27 May 2023 13:10:08 +0000 (14:10 +0100)
Problem:    :stopinsert may not work in a popup close handler. (Ben Jackson)
Solution:   Restore stop_insert_mode when appropriate. (closes #12452,
            closes #12434)

src/autocmd.c
src/testdir/test_quickfix.vim
src/version.c

index c93d4bd754d5f2f6994e7bc9b4a4e4bc3caf002d..862ddf7ccc9fab890c5778122835faaebec336a9 100644 (file)
@@ -1657,11 +1657,13 @@ aucmd_restbuf(
        }
 win_found:
 #ifdef FEAT_JOB_CHANNEL
+       ;
+       int 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;
 #endif
        // Remove the window and frame from the tree of frames.
        (void)winframe_remove(curwin, &dummy, NULL);
index bc180fc04ce8146dfdd1c6a733750963e275bef9..79c169273d3353a850ba8c7f8faa79514231c367 100644 (file)
@@ -6404,5 +6404,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\<C-R>=StopInsert()\<CR>$", '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
index 330914da786566d57137a1230c14d3316aadef7b..7138fee6f1223d3cff3b6a131ef67c2cc2e18c0c 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1582,
 /**/
     1581,
 /**/