Skip to content

Commit f86dea8

Browse files
zeertzjqbrammool
authored andcommitted
patch 9.0.1385: g'Esc is considered an error
Problem: g'Esc is considered an error. Solution: Make g'Esc silently abandon the command. (closes #12110)
1 parent b0b6b8b commit f86dea8

3 files changed

Lines changed: 43 additions & 5 deletions

File tree

src/normal.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ normal_cmd(
899899

900900
State = MODE_NORMAL;
901901

902-
if (ca.nchar == ESC)
902+
if (ca.nchar == ESC || ca.extra_char == ESC)
903903
{
904904
clearop(oap);
905905
if (restart_edit == 0 && goto_im())
@@ -984,7 +984,8 @@ normal_cmd(
984984
#ifdef CURSOR_SHAPE
985985
// Redraw the cursor with another shape, if we were in Operator-pending
986986
// mode or did a replace command.
987-
if (prev_finish_op || ca.cmdchar == 'r')
987+
if (prev_finish_op || ca.cmdchar == 'r'
988+
|| (ca.cmdchar == 'g' && ca.nchar == 'r'))
988989
{
989990
ui_cursor_shape(); // may show different cursor shape
990991
# ifdef FEAT_MOUSESHAPE
@@ -5025,7 +5026,7 @@ nv_vreplace(cmdarg_T *cap)
50255026
return;
50265027
}
50275028

5028-
if (checkclearopq(cap->oap) || cap->extra_char == ESC)
5029+
if (checkclearopq(cap->oap))
50295030
return;
50305031

50315032
if (!curbuf->b_p_ma)
@@ -5903,7 +5904,7 @@ nv_g_cmd(cmdarg_T *cap)
59035904
else
59045905
#endif
59055906
// "g^A/g^X": sequentially increment visually selected region
5906-
if (VIsual_active)
5907+
if (VIsual_active)
59075908
{
59085909
cap->arg = TRUE;
59095910
cap->cmdchar = cap->nchar;

src/testdir/test_normal.vim

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2526,6 +2526,8 @@ func Test_normal33_g_cmd2()
25262526
norm! g'a
25272527
call assert_equal('>', a[-1:])
25282528
call assert_equal(1, line('.'))
2529+
call assert_nobeep("normal! g`\<Esc>")
2530+
call assert_nobeep("normal! g'\<Esc>")
25292531

25302532
" Test for g; and g,
25312533
norm! g;
@@ -3305,7 +3307,8 @@ func Test_gr_command()
33053307
set modifiable&
33063308

33073309
call assert_nobeep("normal! gr\<Esc>")
3308-
call assert_beeps("normal! cgr\<Esc>")
3310+
call assert_nobeep("normal! cgr\<Esc>")
3311+
call assert_beeps("normal! cgrx")
33093312

33103313
call assert_equal('zxxxx line l', getline(1))
33113314
exe "normal! 2|gr\<C-V>\<Esc>"
@@ -3921,4 +3924,36 @@ func Test_mouse_shape_after_failed_change()
39213924
call delete('Xmouseshapes')
39223925
endfunc
39233926

3927+
" Test that mouse shape is restored to Normal mode after cancelling "gr".
3928+
func Test_mouse_shape_after_cancelling_gr()
3929+
CheckFeature mouseshape
3930+
CheckCanRunGui
3931+
3932+
let lines =<< trim END
3933+
vim9script
3934+
var mouse_shapes = []
3935+
3936+
feedkeys('gr')
3937+
timer_start(50, (_) => {
3938+
mouse_shapes += [getmouseshape()]
3939+
timer_start(50, (_) => {
3940+
feedkeys("\<Esc>")
3941+
timer_start(50, (_) => {
3942+
mouse_shapes += [getmouseshape()]
3943+
timer_start(50, (_) => {
3944+
writefile(mouse_shapes, 'Xmouseshapes')
3945+
quit
3946+
})
3947+
})
3948+
})
3949+
})
3950+
END
3951+
call writefile(lines, 'Xmouseshape.vim', 'D')
3952+
call RunVim([], [], "-g -S Xmouseshape.vim")
3953+
sleep 300m
3954+
call assert_equal(['beam', 'arrow'], readfile('Xmouseshapes'))
3955+
3956+
call delete('Xmouseshapes')
3957+
endfunc
3958+
39243959
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1385,
698700
/**/
699701
1384,
700702
/**/

0 commit comments

Comments
 (0)