mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 9.0.1694: wrong mapping applied when replaying a char search
Problem: wrong mapping applied when replaying a char search Solution: Store a NOP after the ESC closes: #12708 closes: #6350 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: zeertzjq <zeertzjq@outlook.com>
This commit is contained in:
parent
2d63e4b3cc
commit
bacc83009b
@ -1338,6 +1338,16 @@ gotchars(char_u *chars, int len)
|
|||||||
++maptick;
|
++maptick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Record a <Nop> key.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gotchars_nop(void)
|
||||||
|
{
|
||||||
|
char_u nop_buf[3] = { K_SPECIAL, KS_EXTRA, KE_NOP };
|
||||||
|
gotchars(nop_buf, 3);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Undo the last gotchars() for "len" bytes. To be used when putting a typed
|
* Undo the last gotchars() for "len" bytes. To be used when putting a typed
|
||||||
* character back into the typeahead buffer, thus gotchars() will be called
|
* character back into the typeahead buffer, thus gotchars() will be called
|
||||||
@ -3656,14 +3666,9 @@ vgetorpeek(int advance)
|
|||||||
#endif
|
#endif
|
||||||
if (timedout && c == ESC)
|
if (timedout && c == ESC)
|
||||||
{
|
{
|
||||||
char_u nop_buf[3];
|
|
||||||
|
|
||||||
// When recording there will be no timeout. Add a <Nop> after the ESC
|
// When recording there will be no timeout. Add a <Nop> after the ESC
|
||||||
// to avoid that it forms a key code with following characters.
|
// to avoid that it forms a key code with following characters.
|
||||||
nop_buf[0] = K_SPECIAL;
|
gotchars_nop();
|
||||||
nop_buf[1] = KS_EXTRA;
|
|
||||||
nop_buf[2] = KE_NOP;
|
|
||||||
gotchars(nop_buf, 3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
--vgetc_busy;
|
--vgetc_busy;
|
||||||
|
42
src/normal.c
42
src/normal.c
@ -543,27 +543,35 @@ normal_cmd_get_more_chars(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When getting a text character and the next character is a
|
if (enc_utf8 && lang)
|
||||||
// multi-byte character, it could be a composing character.
|
|
||||||
// However, don't wait for it to arrive. Also, do enable mapping,
|
|
||||||
// because if it's put back with vungetc() it's too late to apply
|
|
||||||
// mapping.
|
|
||||||
--no_mapping;
|
|
||||||
while (enc_utf8 && lang && (c = vpeekc()) > 0
|
|
||||||
&& (c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1))
|
|
||||||
{
|
{
|
||||||
c = plain_vgetc();
|
// When getting a text character and the next character is a
|
||||||
if (!utf_iscomposing(c))
|
// multi-byte character, it could be a composing character.
|
||||||
|
// However, don't wait for it to arrive. Also, do enable mapping,
|
||||||
|
// because if it's put back with vungetc() it's too late to apply
|
||||||
|
// mapping.
|
||||||
|
--no_mapping;
|
||||||
|
while ((c = vpeekc()) > 0
|
||||||
|
&& (c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1))
|
||||||
{
|
{
|
||||||
vungetc(c); // it wasn't, put it back
|
c = plain_vgetc();
|
||||||
break;
|
if (!utf_iscomposing(c))
|
||||||
|
{
|
||||||
|
vungetc(c); // it wasn't, put it back
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (cap->ncharC1 == 0)
|
||||||
|
cap->ncharC1 = c;
|
||||||
|
else
|
||||||
|
cap->ncharC2 = c;
|
||||||
}
|
}
|
||||||
else if (cap->ncharC1 == 0)
|
++no_mapping;
|
||||||
cap->ncharC1 = c;
|
// Vim may be in a different mode when the user types the next key,
|
||||||
else
|
// but when replaying a recording the next key is already in the
|
||||||
cap->ncharC2 = c;
|
// typeahead buffer, so record a <Nop> before that to prevent the
|
||||||
|
// vpeekc() above from applying wrong mappings when replaying.
|
||||||
|
gotchars_nop();
|
||||||
}
|
}
|
||||||
++no_mapping;
|
|
||||||
}
|
}
|
||||||
--no_mapping;
|
--no_mapping;
|
||||||
--allow_keys;
|
--allow_keys;
|
||||||
|
@ -30,6 +30,7 @@ int typebuf_changed(int tb_change_cnt);
|
|||||||
int typebuf_typed(void);
|
int typebuf_typed(void);
|
||||||
int typebuf_maplen(void);
|
int typebuf_maplen(void);
|
||||||
void del_typebuf(int len, int offset);
|
void del_typebuf(int len, int offset);
|
||||||
|
void gotchars_nop(void);
|
||||||
void ungetchars(int len);
|
void ungetchars(int len);
|
||||||
int save_typebuf(void);
|
int save_typebuf(void);
|
||||||
void save_typeahead(tasave_T *tp);
|
void save_typeahead(tasave_T *tp);
|
||||||
|
@ -797,8 +797,9 @@ func Test_record_in_select_mode()
|
|||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" mapping that ends macro recording should be removed from recorded macro
|
" A mapping that ends recording should be removed from the recorded register.
|
||||||
func Test_end_record_using_mapping()
|
func Test_end_record_using_mapping()
|
||||||
|
new
|
||||||
call setline(1, 'aaa')
|
call setline(1, 'aaa')
|
||||||
nnoremap s q
|
nnoremap s q
|
||||||
call feedkeys('safas', 'tx')
|
call feedkeys('safas', 'tx')
|
||||||
@ -818,7 +819,10 @@ func Test_end_record_using_mapping()
|
|||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Starting a new recording should work immediately after replaying a recording
|
||||||
|
" that ends with a <Nop> mapping or a character search.
|
||||||
func Test_end_reg_executing()
|
func Test_end_reg_executing()
|
||||||
|
new
|
||||||
nnoremap s <Nop>
|
nnoremap s <Nop>
|
||||||
let @a = 's'
|
let @a = 's'
|
||||||
call feedkeys("@aqaq\<Esc>", 'tx')
|
call feedkeys("@aqaq\<Esc>", 'tx')
|
||||||
@ -836,6 +840,26 @@ func Test_end_reg_executing()
|
|||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" An operator-pending mode mapping shouldn't be applied to keys typed in
|
||||||
|
" Insert mode immediately after a character search when replaying.
|
||||||
|
func Test_replay_charsearch_omap()
|
||||||
|
CheckFeature timers
|
||||||
|
|
||||||
|
new
|
||||||
|
call setline(1, 'foo[blah]')
|
||||||
|
onoremap , k
|
||||||
|
call timer_start(10, {-> feedkeys(",bar\<Esc>q", 't')})
|
||||||
|
call feedkeys('qrct[', 'xt!')
|
||||||
|
call assert_equal(',bar[blah]', getline(1))
|
||||||
|
undo
|
||||||
|
call assert_equal('foo[blah]', getline(1))
|
||||||
|
call feedkeys('@r', 'xt!')
|
||||||
|
call assert_equal(',bar[blah]', getline(1))
|
||||||
|
|
||||||
|
ounmap ,
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
|
||||||
" This was causing a crash because y_append was ending up being NULL
|
" This was causing a crash because y_append was ending up being NULL
|
||||||
func Test_zero_y_append()
|
func Test_zero_y_append()
|
||||||
" Run in a separate Vim instance because changing 'encoding' may cause
|
" Run in a separate Vim instance because changing 'encoding' may cause
|
||||||
|
@ -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 */
|
||||||
|
/**/
|
||||||
|
1694,
|
||||||
/**/
|
/**/
|
||||||
1693,
|
1693,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user