changeset 26280:b93e176e7998 v8.2.3671

patch 8.2.3671: restarting Insert mode in prompt buffer too often Commit: https://github.com/vim/vim/commit/34c20ff85b87be587ea5d0398812441b502ee6a5 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Nov 25 13:04:48 2021 +0000 patch 8.2.3671: restarting Insert mode in prompt buffer too often 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.
author Bram Moolenaar <Bram@vim.org>
date Thu, 25 Nov 2021 14:15:03 +0100
parents 63fc72609797
children 41076712e8c3
files src/testdir/test_prompt_buffer.vim src/version.c src/window.c
diffstat 3 files changed, 30 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_prompt_buffer.vim
+++ b/src/testdir/test_prompt_buffer.vim
@@ -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
--- a/src/version.c
+++ b/src/version.c
@@ -758,6 +758,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3671,
+/**/
     3670,
 /**/
     3669,
--- a/src/window.c
+++ b/src/window.c
@@ -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