Skip to content

Commit 4c25bd7

Browse files
committed
patch 8.1.1192: mode is not cleared when leaving Insert mode with mapped Esc
Problem: Mode is not cleared when leaving Insert mode with mapped Esc. Solution: Clear the mode when redraw_cmdline is set. (closes #4269)
1 parent 0fdd943 commit 4c25bd7

4 files changed

Lines changed: 47 additions & 9 deletions

File tree

src/globals.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,13 @@ EXTERN int mod_mask INIT(= 0x0); /* current key modifiers */
9090
*/
9191
EXTERN int cmdline_row;
9292

93-
EXTERN int redraw_cmdline INIT(= FALSE); /* cmdline must be redrawn */
94-
EXTERN int clear_cmdline INIT(= FALSE); /* cmdline must be cleared */
95-
EXTERN int mode_displayed INIT(= FALSE); /* mode is being displayed */
96-
EXTERN int no_win_do_lines_ins INIT(= FALSE); /* don't insert lines */
93+
EXTERN int redraw_cmdline INIT(= FALSE); // cmdline must be redrawn
94+
EXTERN int redraw_mode INIT(= FALSE); // mode must be redrawn
95+
EXTERN int clear_cmdline INIT(= FALSE); // cmdline must be cleared
96+
EXTERN int mode_displayed INIT(= FALSE); // mode is being displayed
97+
EXTERN int no_win_do_lines_ins INIT(= FALSE); // don't insert lines
9798
#if defined(FEAT_CRYPT) || defined(FEAT_EVAL)
98-
EXTERN int cmdline_star INIT(= FALSE); /* cmdline is crypted */
99+
EXTERN int cmdline_star INIT(= FALSE); // cmdline is crypted
99100
#endif
100101

101102
EXTERN int exec_from_reg INIT(= FALSE); /* executing register */

src/screen.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ update_screen(int type_arg)
790790

791791
/* Clear or redraw the command line. Done last, because scrolling may
792792
* mess up the command line. */
793-
if (clear_cmdline || redraw_cmdline)
793+
if (clear_cmdline || redraw_cmdline || redraw_mode)
794794
showmode();
795795

796796
if (no_update)
@@ -857,7 +857,7 @@ update_prepare(void)
857857
static void
858858
update_finish(void)
859859
{
860-
if (redraw_cmdline)
860+
if (redraw_cmdline || redraw_mode)
861861
showmode();
862862

863863
# ifdef FEAT_SEARCH_EXTRA
@@ -10128,7 +10128,7 @@ skip_showmode()
1012810128
|| !redrawing()
1012910129
|| (char_avail() && !KeyTyped))
1013010130
{
10131-
redraw_cmdline = TRUE; // show mode later
10131+
redraw_mode = TRUE; // show mode later
1013210132
return TRUE;
1013310133
}
1013410134
return FALSE;
@@ -10140,6 +10140,7 @@ skip_showmode()
1014010140
* If clear_cmdline is TRUE, clear the rest of the cmdline.
1014110141
* If clear_cmdline is FALSE there may be a message there that needs to be
1014210142
* cleared only if a mode is shown.
10143+
* If redraw_mode is TRUE show or clear the mode.
1014310144
* Return the length of the message (0 if no message).
1014410145
*/
1014510146
int
@@ -10313,7 +10314,7 @@ showmode(void)
1031310314
}
1031410315

1031510316
mode_displayed = TRUE;
10316-
if (need_clear || clear_cmdline)
10317+
if (need_clear || clear_cmdline || redraw_mode)
1031710318
msg_clr_eos();
1031810319
msg_didout = FALSE; /* overwrite this message */
1031910320
length = msg_col;
@@ -10323,6 +10324,11 @@ showmode(void)
1032310324
else if (clear_cmdline && msg_silent == 0)
1032410325
/* Clear the whole command line. Will reset "clear_cmdline". */
1032510326
msg_clr_cmdline();
10327+
else if (redraw_mode)
10328+
{
10329+
msg_pos_mode();
10330+
msg_clr_eos();
10331+
}
1032610332

1032710333
#ifdef FEAT_CMDL_INFO
1032810334
/* In Visual mode the size of the selected area must be redrawn. */
@@ -10335,6 +10341,7 @@ showmode(void)
1033510341
win_redr_ruler(lastwin, TRUE, FALSE);
1033610342
#endif
1033710343
redraw_cmdline = FALSE;
10344+
redraw_mode = FALSE;
1033810345
clear_cmdline = FALSE;
1033910346

1034010347
return length;

src/testdir/test_messages.vim

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,31 @@ func Test_mode_message_at_leaving_insert_by_ctrl_c()
125125
exe buf . 'bwipe!'
126126
call delete(testfile)
127127
endfunc
128+
129+
func Test_mode_message_at_leaving_insert_with_esc_mapped()
130+
if !has('terminal') || has('gui_running')
131+
return
132+
endif
133+
134+
" Set custom statusline built by user-defined function.
135+
let testfile = 'Xtest.vim'
136+
call writefile([
137+
\ 'set laststatus=2',
138+
\ 'inoremap <Esc> <Esc>00',
139+
\ ], testfile)
140+
141+
let rows = 10
142+
let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows})
143+
call term_wait(buf, 200)
144+
call assert_equal('run', job_status(term_getjob(buf)))
145+
146+
call term_sendkeys(buf, "i")
147+
call WaitForAssert({-> assert_match('^-- INSERT --\s*$', term_getline(buf, rows))})
148+
call term_sendkeys(buf, "\<Esc>")
149+
call WaitForAssert({-> assert_match('^\s*$', term_getline(buf, rows))})
150+
151+
call term_sendkeys(buf, ":qall!\<CR>")
152+
call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))})
153+
exe buf . 'bwipe!'
154+
call delete(testfile)
155+
endfunc

src/version.c

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

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1192,
774776
/**/
775777
1191,
776778
/**/

0 commit comments

Comments
 (0)