]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0040: issue with prompt buffer and hidden buffer v9.1.0040
authorzeertzjq <zeertzjq@outlook.com>
Wed, 17 Jan 2024 20:22:59 +0000 (21:22 +0100)
committerChristian Brabandt <cb@256bit.org>
Wed, 17 Jan 2024 20:22:59 +0000 (21:22 +0100)
Problem:  Modifying a hidden buffer still interferes with prompt buffer
          mode changes.
Solution: Save and restore b_prompt_insert.
          (zeertzjq)

closes: #13875

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
Modifying hidden buffer still interferes with prompt buffer mode changes

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

index 8b8f109ea097613dda7600ab8ebd670d4db5d7bf..80ce8ca6c8e055436c18503697fa0d7a4b9f9a33 100644 (file)
@@ -1565,9 +1565,12 @@ 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;
+#ifdef FEAT_JOB_CHANNEL
+    if (bt_prompt(curbuf))
+       aco->save_prompt_insert = curbuf->b_prompt_insert;
+#endif
 
     if (win != NULL)
     {
@@ -1692,6 +1695,8 @@ win_found:
 #ifdef FEAT_JOB_CHANNEL
        // May need to restore insert mode for a prompt buffer.
        entering_window(curwin);
+       if (bt_prompt(curbuf))
+           curbuf->b_prompt_insert = aco->save_prompt_insert;
 #endif
        prevwin = win_find_by_id(aco->save_prevwin_id);
 #ifdef FEAT_EVAL
index 76f143305b755e4f80d09aafba19ef50fa0d17b1..5b88260f357e1c5c7036b992ce6b4a8778149cf7 100644 (file)
@@ -4358,7 +4358,6 @@ typedef int vimmenu_T;
  */
 typedef struct
 {
-    buf_T      *save_curbuf;       // saved curbuf
     int                use_aucmd_win_idx;  // index in aucmd_win[] if >= 0
     int                save_curwin_id;     // ID of saved curwin
     int                new_curwin_id;      // ID of new curwin
@@ -4367,6 +4366,9 @@ typedef struct
     char_u     *globaldir;         // saved value of globaldir
     int                save_VIsual_active; // saved VIsual_active
     int                save_State;         // saved State
+#ifdef FEAT_JOB_CHANNEL
+    int                save_prompt_insert; // saved b_prompt_insert
+#endif
 } aco_save_T;
 
 /*
index 81a293db0e40b4f0562670c3975264457e34f7a9..c5ef0103431d85fdd094da436f7fd25aa4417e09 100644 (file)
@@ -297,9 +297,10 @@ 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()
+" Modifying a hidden buffer while leaving a prompt buffer should not prevent
+" stopping of Insert mode, and returning to the prompt buffer later should
+" restore Insert mode.
+func Test_prompt_leave_modify_hidden()
   call CanTestPromptBuffer()
 
   let script =<< trim END
@@ -309,22 +310,34 @@ func Test_prompt_close_modify_hidden()
       new prompt
       set buftype=prompt
 
+      inoremap <buffer> w <Cmd>wincmd w<CR>
       inoremap <buffer> q <Cmd>bwipe!<CR>
-      autocmd BufWinLeave prompt call setbufline('hidden', 1, 'Test')
+      autocmd BufLeave prompt call appendbufline('hidden', '$', 'Leave')
+      autocmd BufEnter prompt call appendbufline('hidden', '$', 'Enter')
+      autocmd BufWinLeave prompt call appendbufline('hidden', '$', 'Close')
   END
-  call writefile(script, 'XpromptCloseModifyHidden', 'D')
+  call writefile(script, 'XpromptLeaveModifyHidden', 'D')
 
-  let buf = RunVimInTerminal('-S XpromptCloseModifyHidden', {'rows': 10})
+  let buf = RunVimInTerminal('-S XpromptLeaveModifyHidden', {'rows': 10})
   call TermWait(buf)
 
   call term_sendkeys(buf, "a")
   call WaitForAssert({-> assert_match('-- INSERT --', term_getline(buf, 10))})
 
+  call term_sendkeys(buf, "w")
+  call WaitForAssert({-> assert_notmatch('-- INSERT --', term_getline(buf, 10))})
+
+  call term_sendkeys(buf, "\<C-W>w")
+  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 WaitForAssert({-> assert_equal('Leave', term_getline(buf, 2))})
+  call WaitForAssert({-> assert_equal('Enter', term_getline(buf, 3))})
+  call WaitForAssert({-> assert_equal('Leave', term_getline(buf, 4))})
+  call WaitForAssert({-> assert_equal('Close', term_getline(buf, 5))})
 
   call StopVimInTerminal(buf)
 endfunc
index e3272f1e4b6c9fb07b51dcbf91aad864fee84e2f..924c6f175022b2bf4fea7d3cf08dd70aab00f3f1 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    40,
 /**/
     39,
 /**/