]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0033: Insert mode not stopped if closing prompt buffer modifies hidden... v9.1.0033
authorzeertzjq <zeertzjq@outlook.com>
Tue, 16 Jan 2024 16:19:59 +0000 (17:19 +0100)
committerChristian Brabandt <cb@256bit.org>
Tue, 16 Jan 2024 16:21:04 +0000 (17:21 +0100)
Problem:  Insert mode not stopped if an autocommand modifies a hidden
          buffer while closing a prompt buffer.
Solution: Don't set b_prompt_insert if stop_insert_mode is already set.
          (zeertzjq)

closes: #13872

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_prompt_buffer.vim
src/version.c
src/window.c

index d17373160783885f6091357668d291481087211e..81a293db0e40b4f0562670c3975264457e34f7a9 100644 (file)
@@ -297,4 +297,36 @@ func Test_prompt_appending_while_hidden()
   call StopVimInTerminal(buf)
 endfunc
 
+" Modifying a hidden buffer while closing a prompt buffer should not prevent
+" stopping of Insert mode.
+func Test_prompt_close_modify_hidden()
+  call CanTestPromptBuffer()
+
+  let script =<< trim END
+      file hidden
+      set bufhidden=hide
+      enew
+      new prompt
+      set buftype=prompt
+
+      inoremap <buffer> q <Cmd>bwipe!<CR>
+      autocmd BufWinLeave prompt call setbufline('hidden', 1, 'Test')
+  END
+  call writefile(script, 'XpromptCloseModifyHidden', 'D')
+
+  let buf = RunVimInTerminal('-S XpromptCloseModifyHidden', {'rows': 10})
+  call TermWait(buf)
+
+  call term_sendkeys(buf, "a")
+  call WaitForAssert({-> assert_match('-- INSERT --', term_getline(buf, 10))})
+
+  call term_sendkeys(buf, "q")
+  call WaitForAssert({-> assert_notmatch('-- INSERT --', term_getline(buf, 10))})
+
+  call term_sendkeys(buf, ":bwipe!\<CR>")
+  call WaitForAssert({-> assert_equal('Test', term_getline(buf, 1))})
+
+  call StopVimInTerminal(buf)
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 2e32ae1d1b46f2fd1bcc9c6d19d27a818c214ca3..9f80e8276b007e1560dbd3bb0f1c3c8cf9ec4e57 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    33,
 /**/
     32,
 /**/
index e53ac7158496d15e9932ef9e5fdcc5c9b8022b9e..d9d3401e648b08bcf95b991b89b061825db34421 100644 (file)
@@ -2362,7 +2362,7 @@ leaving_window(win_T *win)
     // When leaving the window (or closing the window) was done from a
     // callback we need to break out of the Insert mode loop and restart Insert
     // mode when entering the window again.
-    if (State & MODE_INSERT)
+    if ((State & MODE_INSERT) && !stop_insert_mode)
     {
        stop_insert_mode = TRUE;
        if (win->w_buffer->b_prompt_insert == NUL)