0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 9.0.1356: cannot cancel "gr" with Esc

Problem:    Cannot cancel "gr" with Esc.
Solution:   Make "gr<Esc>" do nothing. (closes #12064)
This commit is contained in:
zeertzjq 2023-02-26 14:47:24 +00:00 committed by Bram Moolenaar
parent 83ae6150bf
commit 4f026ea9f1
5 changed files with 32 additions and 28 deletions

View File

@ -45,7 +45,7 @@ static void ins_ctrl_(void);
#endif #endif
static int ins_start_select(int c); static int ins_start_select(int c);
static void ins_insert(int replaceState); static void ins_insert(int replaceState);
static void ins_ctrl_o(int cmdchar); static void ins_ctrl_o(void);
static void ins_shift(int c, int lastc); static void ins_shift(int c, int lastc);
static void ins_del(void); static void ins_del(void);
static int ins_bs(int c, int mode, int *inserted_space_p); static int ins_bs(int c, int mode, int *inserted_space_p);
@ -429,8 +429,7 @@ edit(
/* /*
* Main loop in Insert mode: repeat until Insert mode is left. * Main loop in Insert mode: repeat until Insert mode is left.
*/ */
int did_loop = FALSE; for (;;)
for (;; did_loop = TRUE)
{ {
#ifdef FEAT_RIGHTLEFT #ifdef FEAT_RIGHTLEFT
if (!revins_legal) if (!revins_legal)
@ -589,8 +588,6 @@ edit(
if (cmdchar == K_PS) if (cmdchar == K_PS)
// Got here from normal mode when bracketed paste started. // Got here from normal mode when bracketed paste started.
c = K_PS; c = K_PS;
else if (cmdchar == 'v' && did_loop && count <= 0)
c = ESC; // in case the stuffed Esc was consumed already
else else
do do
{ {
@ -720,7 +717,7 @@ edit(
{ {
if (c == Ctrl_O) if (c == Ctrl_O)
{ {
ins_ctrl_o(cmdchar); ins_ctrl_o();
ins_at_eol = FALSE; // cursor keeps its column ins_at_eol = FALSE; // cursor keeps its column
nomove = TRUE; nomove = TRUE;
} }
@ -863,7 +860,7 @@ doESCkey:
#endif #endif
if (echeck_abbr(Ctrl_O + ABBR_OFF)) if (echeck_abbr(Ctrl_O + ABBR_OFF))
break; break;
ins_ctrl_o(cmdchar); ins_ctrl_o();
// don't move the cursor left when 'virtualedit' has "onemore". // don't move the cursor left when 'virtualedit' has "onemore".
if (get_ve_flags() & VE_ONEMORE) if (get_ve_flags() & VE_ONEMORE)
@ -3855,10 +3852,8 @@ ins_insert(int replaceState)
* Pressed CTRL-O in Insert mode. * Pressed CTRL-O in Insert mode.
*/ */
static void static void
ins_ctrl_o(int cmdchar) ins_ctrl_o(void)
{ {
if (cmdchar == 'v')
return; // abort replacing one char for gr CTRL-O
if (State & VREPLACE_FLAG) if (State & VREPLACE_FLAG)
restart_edit = 'V'; restart_edit = 'V';
else if (State & REPLACE_FLAG) else if (State & REPLACE_FLAG)

View File

@ -515,7 +515,8 @@ normal_cmd_get_more_chars(
cap->nchar = cap->extra_char; cap->nchar = cap->extra_char;
idx = find_command(cap->cmdchar); idx = find_command(cap->cmdchar);
} }
else if ((cap->nchar == 'n' || cap->nchar == 'N') && cap->cmdchar == 'g') else if ((cap->nchar == 'n' || cap->nchar == 'N')
&& cap->cmdchar == 'g')
cap->oap->op_type = get_op_type(*cp, NUL); cap->oap->op_type = get_op_type(*cp, NUL);
else if (*cp == Ctrl_BSL) else if (*cp == Ctrl_BSL)
{ {
@ -5024,7 +5025,7 @@ nv_vreplace(cmdarg_T *cap)
return; return;
} }
if (checkclearopq(cap->oap)) if (checkclearopq(cap->oap) || cap->extra_char == ESC)
return; return;
if (!curbuf->b_p_ma) if (!curbuf->b_p_ma)

View File

@ -573,6 +573,7 @@ func Test_edit_CTRL_G()
call assert_equal([0, 3, 7, 0], getpos('.')) call assert_equal([0, 3, 7, 0], getpos('.'))
call feedkeys("i\<c-g>j\<esc>", 'tnix') call feedkeys("i\<c-g>j\<esc>", 'tnix')
call assert_equal([0, 3, 6, 0], getpos('.')) call assert_equal([0, 3, 6, 0], getpos('.'))
call assert_nobeep("normal! i\<c-g>\<esc>")
bw! bw!
endfunc endfunc
@ -2064,20 +2065,6 @@ func Test_edit_CTRL_hat()
bwipe! bwipe!
endfunc endfunc
" Test "gr" followed by an Insert mode command does get out of Insert mode.
func Test_edit_gr_special()
enew
call setline(1, ['abcdef', 'xxxxxx'])
exe "normal! gr\<C-O>lx"
call assert_equal("\<C-O>def", getline(1))
call setline(1, 'abcdef')
exe "normal! 0gr\<C-G>lx"
call assert_equal("\<C-G>def", getline(1))
bwipe!
endfunc
" Weird long file name was going over the end of NameBuff " Weird long file name was going over the end of NameBuff
func Test_edit_overlong_file_name() func Test_edit_overlong_file_name()
CheckUnix CheckUnix

View File

@ -3273,9 +3273,9 @@ func Test_delete_until_paragraph()
endfunc endfunc
" Test for the gr (virtual replace) command " Test for the gr (virtual replace) command
" Test for the bug fixed by 7.4.387
func Test_gr_command() func Test_gr_command()
enew! enew!
" Test for the bug fixed by 7.4.387
let save_cpo = &cpo let save_cpo = &cpo
call append(0, ['First line', 'Second line', 'Third line']) call append(0, ['First line', 'Second line', 'Third line'])
exe "normal i\<C-G>u" exe "normal i\<C-G>u"
@ -3288,10 +3288,12 @@ func Test_gr_command()
normal 4gro normal 4gro
call assert_equal('ooooecond line', getline(2)) call assert_equal('ooooecond line', getline(2))
let &cpo = save_cpo let &cpo = save_cpo
normal! ggvegrx normal! ggvegrx
call assert_equal('xxxxx line', getline(1)) call assert_equal('xxxxx line', getline(1))
exe "normal! gggr\<C-V>122" exe "normal! gggr\<C-V>122"
call assert_equal('zxxxx line', getline(1)) call assert_equal('zxxxx line', getline(1))
set virtualedit=all set virtualedit=all
normal! 15|grl normal! 15|grl
call assert_equal('zxxxx line l', getline(1)) call assert_equal('zxxxx line l', getline(1))
@ -3299,8 +3301,25 @@ func Test_gr_command()
set nomodifiable set nomodifiable
call assert_fails('normal! grx', 'E21:') call assert_fails('normal! grx', 'E21:')
call assert_fails('normal! gRx', 'E21:') call assert_fails('normal! gRx', 'E21:')
call assert_nobeep("normal! gr\<Esc>")
set modifiable& set modifiable&
enew!
call assert_nobeep("normal! gr\<Esc>")
call assert_beeps("normal! cgr\<Esc>")
call assert_equal('zxxxx line l', getline(1))
exe "normal! 2|gr\<C-V>\<Esc>"
call assert_equal("z\<Esc>xx line l", getline(1))
call setline(1, 'abcdef')
exe "normal! 0gr\<C-O>lx"
call assert_equal("\<C-O>def", getline(1))
call setline(1, 'abcdef')
exe "normal! 0gr\<C-G>lx"
call assert_equal("\<C-G>def", getline(1))
bwipe!
endfunc endfunc
func Test_nv_hat_count() func Test_nv_hat_count()

View File

@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1356,
/**/ /**/
1355, 1355,
/**/ /**/