Skip to content

Commit 891e1fd

Browse files
committed
patch 8.1.0036: not restoring Insert mode if leaving prompt buffer with mouse
Problem: Not restoring Insert mode if leaving a prompt buffer by using a mouse click. Solution: Set b_prompt_insert appropriately. Also correct cursor position when moving cursor to last line.
1 parent 6d41c78 commit 891e1fd

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

src/buffer.c

+4
Original file line numberDiff line numberDiff line change
@@ -5733,6 +5733,10 @@ buf_spname(buf_T *buf)
57335733
#endif
57345734
if (buf->b_fname != NULL)
57355735
return buf->b_fname;
5736+
#ifdef FEAT_JOB_CHANNEL
5737+
if (bt_prompt(buf))
5738+
return (char_u *)_("[Prompt]");
5739+
#endif
57365740
return (char_u *)_("[Scratch]");
57375741
}
57385742

src/edit.c

+11-5
Original file line numberDiff line numberDiff line change
@@ -1411,11 +1411,10 @@ edit(
14111411
#ifdef FEAT_JOB_CHANNEL
14121412
if (bt_prompt(curbuf))
14131413
{
1414-
buf_T *buf = curbuf;
1415-
14161414
invoke_prompt_callback();
1417-
if (curbuf != buf)
1418-
// buffer changed, get out of Insert mode
1415+
if (!bt_prompt(curbuf))
1416+
// buffer changed to a non-prompt buffer, get out of
1417+
// Insert mode
14191418
goto doESCkey;
14201419
break;
14211420
}
@@ -1906,6 +1905,8 @@ init_prompt(int cmdchar_todo)
19061905
coladvance((colnr_T)MAXCOL);
19071906
if (cmdchar_todo == 'I' || curwin->w_cursor.col <= (int)STRLEN(prompt))
19081907
curwin->w_cursor.col = STRLEN(prompt);
1908+
/* Make sure the cursor is in a valid position. */
1909+
check_cursor();
19091910
}
19101911

19111912
/*
@@ -9467,7 +9468,7 @@ ins_bs(
94679468

94689469
/* If deleted before the insertion point, adjust it */
94699470
if (curwin->w_cursor.lnum == Insstart_orig.lnum
9470-
&& curwin->w_cursor.col < Insstart_orig.col)
9471+
&& curwin->w_cursor.col < Insstart_orig.col)
94719472
Insstart_orig.col = curwin->w_cursor.col;
94729473

94739474
/* vi behaviour: the cursor moves backward but the character that
@@ -9517,6 +9518,11 @@ ins_mouse(int c)
95179518
* previous one to stop insert there properly. */
95189519
curwin = old_curwin;
95199520
curbuf = curwin->w_buffer;
9521+
#ifdef FEAT_JOB_CHANNEL
9522+
if (bt_prompt(curbuf))
9523+
// Restart Insert mode when re-entering the prompt buffer.
9524+
curbuf->b_prompt_insert = 'A';
9525+
#endif
95209526
}
95219527
start_arrow(curwin == old_curwin ? &tpos : NULL);
95229528
if (curwin != new_curwin && win_valid(new_curwin))

src/version.c

+2
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
36,
764766
/**/
765767
35,
766768
/**/

src/window.c

+9
Original file line numberDiff line numberDiff line change
@@ -2115,12 +2115,21 @@ leaving_window(win_T *win)
21152115
// When leaving the window (or closing the window) was done from a
21162116
// callback we need to break out of the Insert mode loop.
21172117
if (State & INSERT)
2118+
{
21182119
stop_insert_mode = TRUE;
2120+
if (bt_prompt(win->w_buffer) && win->w_buffer->b_prompt_insert == NUL)
2121+
win->w_buffer->b_prompt_insert = 'A';
2122+
}
21192123
}
21202124

21212125
static void
21222126
entering_window(win_T *win)
21232127
{
2128+
// When switching to a prompt buffer that was in Insert mode, don't stop
2129+
// Insert mode, it may have been set in leaving_window().
2130+
if (bt_prompt(win->w_buffer) && win->w_buffer->b_prompt_insert != NUL)
2131+
stop_insert_mode = FALSE;
2132+
21242133
// When entering the prompt window may restart Insert mode.
21252134
restart_edit = win->w_buffer->b_prompt_insert;
21262135
}

0 commit comments

Comments
 (0)