@@ -2103,6 +2103,29 @@ win_equal_rec(
21032103 }
21042104}
21052105
2106+ #ifdef FEAT_JOB_CHANNEL
2107+ static void
2108+ leaving_window (win_T * win )
2109+ {
2110+ // When leaving a prompt window stop Insert mode and perhaps restart
2111+ // it when entering that window again.
2112+ win -> w_buffer -> b_prompt_insert = restart_edit ;
2113+ restart_edit = NUL ;
2114+
2115+ // When leaving the window (or closing the window) was done from a
2116+ // callback we need to break out of the Insert mode loop.
2117+ if (State & INSERT )
2118+ stop_insert_mode = TRUE;
2119+ }
2120+
2121+ static void
2122+ entering_window (win_T * win )
2123+ {
2124+ // When entering the prompt window may restart Insert mode.
2125+ restart_edit = win -> w_buffer -> b_prompt_insert ;
2126+ }
2127+ #endif
2128+
21062129/*
21072130 * Close all windows for buffer "buf".
21082131 */
@@ -2231,6 +2254,9 @@ close_last_window_tabpage(
22312254 if (h != tabline_height ())
22322255 shell_new_rows ();
22332256 }
2257+ #ifdef FEAT_JOB_CHANNEL
2258+ entering_window (curwin );
2259+ #endif
22342260 /* Since goto_tabpage_tp above did not trigger *Enter autocommands, do
22352261 * that now. */
22362262 apply_autocmds (EVENT_TABCLOSED , NULL , NULL , FALSE, curbuf );
@@ -2296,6 +2322,9 @@ win_close(win_T *win, int free_buf)
22962322
22972323 if (win == curwin )
22982324 {
2325+ #ifdef FEAT_JOB_CHANNEL
2326+ leaving_window (curwin );
2327+ #endif
22992328 /*
23002329 * Guess which window is going to be the new current window.
23012330 * This may change because of the autocommands (sigh).
@@ -3649,6 +3678,9 @@ win_new_tabpage(int after)
36493678 * scrollbars. Have to update them anyway. */
36503679 gui_may_update_scrollbars ();
36513680#endif
3681+ #ifdef FEAT_JOB_CHANNEL
3682+ entering_window (curwin );
3683+ #endif
36523684
36533685 redraw_all_later (CLEAR );
36543686 apply_autocmds (EVENT_WINNEW , NULL , NULL , FALSE, curbuf );
@@ -3822,6 +3854,9 @@ leave_tabpage(
38223854{
38233855 tabpage_T * tp = curtab ;
38243856
3857+ #ifdef FEAT_JOB_CHANNEL
3858+ leaving_window (curwin );
3859+ #endif
38253860 reset_VIsual_and_resel (); /* stop Visual mode */
38263861 if (trigger_leave_autocmds )
38273862 {
@@ -4318,6 +4353,11 @@ win_enter_ext(
43184353 if (wp == curwin && !curwin_invalid ) /* nothing to do */
43194354 return ;
43204355
4356+ #ifdef FEAT_JOB_CHANNEL
4357+ if (!curwin_invalid )
4358+ leaving_window (curwin );
4359+ #endif
4360+
43214361 if (!curwin_invalid && trigger_leave_autocmds )
43224362 {
43234363 /*
@@ -4389,6 +4429,9 @@ win_enter_ext(
43894429 shorten_fnames (TRUE);
43904430 }
43914431
4432+ #ifdef FEAT_JOB_CHANNEL
4433+ entering_window (curwin );
4434+ #endif
43924435 if (trigger_new_autocmds )
43934436 apply_autocmds (EVENT_WINNEW , NULL , NULL , FALSE, curbuf );
43944437 if (trigger_enter_autocmds )
0 commit comments