]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1439: start Insert mode when accessing a hidden prompt buffer v9.0.1439
authororbital <orbital@holgerines.de>
Sun, 2 Apr 2023 21:05:13 +0000 (22:05 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 2 Apr 2023 21:05:13 +0000 (22:05 +0100)
Problem:    Start Insert mode when accessing a hidden prompt buffer.
Solution:   Call leaving_window() in aucmd_restbuf(). (Thorben Tröbst,
            closes #12148, closes #12147)

src/autocmd.c
src/proto/window.pro
src/testdir/test_prompt_buffer.vim
src/version.c
src/window.c

index fe2b6cbb14d429cb0d4efd0081ab89a8b34ff08f..e5f512503a1846bc1219bbceef1011674897bc47 100644 (file)
@@ -1657,7 +1657,10 @@ aucmd_restbuf(
            }
        }
 win_found:
-
+#ifdef FEAT_JOB_CHANNEL
+       // May need to stop Insert mode if we were in a prompt buffer.
+       leaving_window(curwin);
+#endif
        // Remove the window and frame from the tree of frames.
        (void)winframe_remove(curwin, &dummy, NULL);
        win_remove(curwin, NULL);
index 6522466bed31e985b8c1d8b3dfb7dcb1a2ce6ce5..d1108af50b79f45487b3a56f6b618d2a01351968 100644 (file)
@@ -13,6 +13,7 @@ int win_count(void);
 int make_windows(int count, int vertical);
 void win_move_after(win_T *win1, win_T *win2);
 void win_equal(win_T *next_curwin, int current, int dir);
+void leaving_window(win_T *win);
 void entering_window(win_T *win);
 void curwin_init(void);
 void close_windows(buf_T *buf, int keep_curwin);
index 9998cc5da241bbbbecfa90eb87bec9638792bb0a..28e0d765f2f609bc856a5294ad4fb25a767f0b1c 100644 (file)
@@ -252,4 +252,42 @@ func Test_prompt_while_writing_to_hidden_buffer()
   call StopVimInTerminal(buf)
 endfunc
 
+func Test_prompt_appending_while_hidden()
+  call CanTestPromptBuffer()
+
+  let script =<< trim END
+      new prompt
+      set buftype=prompt
+      set bufhidden=hide
+
+      func s:TextEntered(text)
+          if a:text == 'exit'
+              close
+          endif
+          echowin 'Entered:' a:text
+      endfunc
+      call prompt_setcallback(bufnr(), function('s:TextEntered'))
+
+      func DoAppend()
+        call appendbufline('prompt', '$', 'Test')
+      endfunc
+  END
+  call writefile(script, 'XpromptBuffer', 'D')
+
+  let buf = RunVimInTerminal('-S XpromptBuffer', {'rows': 10})
+  call TermWait(buf)
+
+  call term_sendkeys(buf, "asomething\<CR>")
+  call TermWait(buf)
+
+  call term_sendkeys(buf, "exit\<CR>")
+  call TermWait(buf)
+
+  call term_sendkeys(buf, ":call DoAppend()\<CR>")
+  call TermWait(buf)
+  call assert_notmatch('-- INSERT --', term_getline(buf, 10))
+
+  call StopVimInTerminal(buf)
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 47ecd534eed22e3ae96a95d49b90c0ae1147a0ad..5cace2e388578419842d7de3b860f4a44b995523 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1439,
 /**/
     1438,
 /**/
index a967f92179ec7a83d97e34d4d7636c0c475ac75f..3405285c05791b92eb1da6a912af1995d64ffbe2 100644 (file)
@@ -2292,7 +2292,7 @@ win_equal_rec(
 }
 
 #ifdef FEAT_JOB_CHANNEL
-    static void
+    void
 leaving_window(win_T *win)
 {
     // Only matters for a prompt window.