Skip to content

Commit 8ad16da

Browse files
committed
patch 8.1.0696: when test_edit fails 'insertmode' may not be reset
Problem: When test_edit fails 'insertmode' may not be reset and the next test may get stuck. (James McCoy) Solution: Always reset 'insertmode' after executing a test. Avoid that an InsertCharPre autocommand or a 'complete' function can change the state. (closes #3768)
1 parent f42b45d commit 8ad16da

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/edit.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4219,6 +4219,7 @@ expand_by_function(
42194219
win_T *curwin_save;
42204220
buf_T *curbuf_save;
42214221
typval_T rettv;
4222+
int save_State = State;
42224223

42234224
funcname = (type == CTRL_X_FUNCTION) ? curbuf->b_p_cfu : curbuf->b_p_ofu;
42244225
if (*funcname == NUL)
@@ -4272,6 +4273,9 @@ expand_by_function(
42724273
ins_compl_add_dict(matchdict);
42734274

42744275
theend:
4276+
// Restore State, it might have been changed.
4277+
State = save_State;
4278+
42754279
if (matchdict != NULL)
42764280
dict_unref(matchdict);
42774281
if (matchlist != NULL)
@@ -5549,6 +5553,7 @@ ins_complete(int c, int enable_pum)
55495553
pos_T pos;
55505554
win_T *curwin_save;
55515555
buf_T *curbuf_save;
5556+
int save_State = State;
55525557

55535558
/* Call 'completefunc' or 'omnifunc' and get pattern length as a
55545559
* string */
@@ -5572,6 +5577,8 @@ ins_complete(int c, int enable_pum)
55725577
curwin_save = curwin;
55735578
curbuf_save = curbuf;
55745579
col = call_func_retnr(funcname, 2, args);
5580+
5581+
State = save_State;
55755582
if (curwin_save != curwin || curbuf_save != curbuf)
55765583
{
55775584
EMSG(_(e_complwin));
@@ -10730,6 +10737,7 @@ do_insert_char_pre(int c)
1073010737
{
1073110738
char_u *res;
1073210739
char_u buf[MB_MAXBYTES + 1];
10740+
int save_State = State;
1073310741

1073410742
/* Return quickly when there is nothing to do. */
1073510743
if (!has_insertcharpre())
@@ -10762,6 +10770,9 @@ do_insert_char_pre(int c)
1076210770
set_vim_var_string(VV_CHAR, NULL, -1); /* clear v:char */
1076310771
--textlock;
1076410772

10773+
// Restore the State, it may have been changed.
10774+
State = save_State;
10775+
1076510776
return res;
1076610777
}
1076710778
#endif

src/testdir/runtest.vim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
" It will be called after each Test_ function.
2727
"
2828
" When debugging a test it can be useful to add messages to v:errors:
29-
" call add(v:errors, "this happened")
29+
" call add(v:errors, "this happened")
3030

3131

3232
" Without the +eval feature we can't run these tests, bail out.
@@ -149,6 +149,10 @@ func RunTheTest(test)
149149
endtry
150150
endif
151151

152+
" In case 'insertmode' was set and something went wrong, make sure it is
153+
" reset to avoid trouble with anything else.
154+
set noinsertmode
155+
152156
if exists("*TearDown")
153157
try
154158
call TearDown()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,8 @@ static char *(features[]) =
799799

800800
static int included_patches[] =
801801
{ /* Add new patch number below this line */
802+
/**/
803+
696,
802804
/**/
803805
695,
804806
/**/

0 commit comments

Comments
 (0)