]> granicus.if.org Git - vim/commitdiff
patch 8.2.3671: restarting Insert mode in prompt buffer too often v8.2.3671
authorBram Moolenaar <Bram@vim.org>
Thu, 25 Nov 2021 13:04:48 +0000 (13:04 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 25 Nov 2021 13:04:48 +0000 (13:04 +0000)
Problem:    Restarting Insert mode in prompt buffer too often when a callback
            switches windows and comes back. (Sean Dewar)
Solution:   Do not set "restart_edit" when already in Insert mode.

src/testdir/test_prompt_buffer.vim
src/version.c
src/window.c

index 32ed21e640cb3219b0ca8c19810396c05dc3484f..8918bd47f236317e3c99009b12596aaaf0b4dce2 100644 (file)
@@ -39,6 +39,10 @@ func WriteScript(name)
        \ '  set nomodified',
        \ 'endfunc',
        \ '',
+       \ 'func SwitchWindows()',
+       \ '  call timer_start(0, {-> execute("wincmd p|wincmd p", "")})',
+       \ 'endfunc',
+       \ '',
        \ 'call setline(1, "other buffer")',
        \ 'set nomodified',
        \ 'new',
@@ -99,6 +103,27 @@ func Test_prompt_editing()
   call delete(scriptName)
 endfunc
 
+func Test_prompt_switch_windows()
+  call CanTestPromptBuffer()
+  let scriptName = 'XpromptSwitchWindows'
+  call WriteScript(scriptName)
+
+  let buf = RunVimInTerminal('-S ' . scriptName, {'rows': 12})
+  call WaitForAssert({-> assert_equal('cmd:', term_getline(buf, 1))})
+  call WaitForAssert({-> assert_match('-- INSERT --', term_getline(buf, 12))})
+
+  call term_sendkeys(buf, "\<C-O>:call SwitchWindows()\<CR>")
+  call term_wait(buf, 50)
+  call WaitForAssert({-> assert_match('-- INSERT --', term_getline(buf, 12))})
+
+  call term_sendkeys(buf, "\<Esc>")
+  call term_wait(buf, 50)
+  call WaitForAssert({-> assert_match('^ *$', term_getline(buf, 12))})
+
+  call StopVimInTerminal(buf)
+  call delete(scriptName)
+endfunc
+
 func Test_prompt_garbage_collect()
   func MyPromptCallback(x, text)
     " NOP
index 19188904dd2c42a14c6ba1ef49be59ec9d0bb127..0686cfab905b995e011252e30473e6270a65bb24 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3671,
 /**/
     3670,
 /**/
index d28962a308dc293a2c9a7b9381df2223ba8e57c1..4fbf94428ca0eaf3df0f56179c676a3999488c38 100644 (file)
@@ -2268,8 +2268,9 @@ entering_window(win_T *win)
        stop_insert_mode = FALSE;
 
     // When entering the prompt window restart Insert mode if we were in Insert
-    // mode when we left it.
-    restart_edit = win->w_buffer->b_prompt_insert;
+    // mode when we left it and not already in Insert mode.
+    if ((State & INSERT) == 0)
+       restart_edit = win->w_buffer->b_prompt_insert;
 }
 #endif