]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1443: ending Insert mode when accessing a hidden prompt buffer v9.0.1443
authorBram Moolenaar <Bram@vim.org>
Sun, 9 Apr 2023 21:01:31 +0000 (22:01 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 9 Apr 2023 21:01:31 +0000 (22:01 +0100)
Problem:    Ending Insert mode when accessing a hidden prompt buffer.
Solution:   Don't stop Insert mode when it was active before. (closes #12237)

src/autocmd.c
src/structs.h
src/testdir/test_prompt_buffer.vim
src/version.c

index e5f512503a1846bc1219bbceef1011674897bc47..6460fcdc6457877d7a270c0323ca4101676b1ac8 100644 (file)
@@ -1566,6 +1566,8 @@ aucmd_prepbuf(
     aco->save_curwin_id = curwin->w_id;
     aco->save_curbuf = curbuf;
     aco->save_prevwin_id = prevwin == NULL ? 0 : prevwin->w_id;
+    aco->save_State = State;
+
     if (win != NULL)
     {
        // There is a window for "buf" in the current tab page, make it the
@@ -1660,6 +1662,9 @@ win_found:
 #ifdef FEAT_JOB_CHANNEL
        // 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;
 #endif
        // Remove the window and frame from the tree of frames.
        (void)winframe_remove(curwin, &dummy, NULL);
index 39248a7e48e8b97f98d7d61396dcab795693691a..9500139080f8228cbd63e26ca6d180415228545f 100644 (file)
@@ -4274,6 +4274,7 @@ typedef struct
     bufref_T   new_curbuf;         // new curbuf
     char_u     *globaldir;         // saved value of globaldir
     int                save_VIsual_active; // saved VIsual_active
+    int                save_State;         // saved State
 } aco_save_T;
 
 /*
index 28e0d765f2f609bc856a5294ad4fb25a767f0b1c..b81309c71e731a4ebd45e29e2ab03855b8b55590 100644 (file)
@@ -270,6 +270,7 @@ func Test_prompt_appending_while_hidden()
 
       func DoAppend()
         call appendbufline('prompt', '$', 'Test')
+        return ''
       endfunc
   END
   call writefile(script, 'XpromptBuffer', 'D')
@@ -282,11 +283,21 @@ func Test_prompt_appending_while_hidden()
 
   call term_sendkeys(buf, "exit\<CR>")
   call TermWait(buf)
+  call assert_notmatch('-- INSERT --', term_getline(buf, 10))
 
   call term_sendkeys(buf, ":call DoAppend()\<CR>")
   call TermWait(buf)
   call assert_notmatch('-- INSERT --', term_getline(buf, 10))
 
+  call term_sendkeys(buf, "i")
+  call TermWait(buf)
+  call assert_match('-- INSERT --', term_getline(buf, 10))
+
+  call term_sendkeys(buf, "\<C-R>=DoAppend()\<CR>")
+  call TermWait(buf)
+  call assert_match('-- INSERT --', term_getline(buf, 10))
+
+  call term_sendkeys(buf, "\<Esc>")
   call StopVimInTerminal(buf)
 endfunc
 
index 192d58278757fcbcff41577b88377d92fde2b6c8..eba3db43c3515b34ccac6d37238193ea0013a36d 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1443,
 /**/
     1442,
 /**/