mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
vim-patch:9.0.1694: wrong mapping applied when replaying a char search (#24670)
Problem: wrong mapping applied when replaying a char search
Solution: Store a NOP after the ESC
closes: vim/vim#12708
closes: vim/vim#6350
bacc83009b
This commit is contained in:
@@ -1147,6 +1147,13 @@ static void gotchars(const uint8_t *chars, size_t len)
|
|||||||
maptick++;
|
maptick++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Record a <Nop> key.
|
||||||
|
void gotchars_nop(void)
|
||||||
|
{
|
||||||
|
uint8_t 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
|
||||||
/// again.
|
/// again.
|
||||||
@@ -2745,14 +2752,9 @@ static int vgetorpeek(bool advance)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (timedout && c == ESC) {
|
if (timedout && c == ESC) {
|
||||||
uint8_t 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--;
|
||||||
|
@@ -807,6 +807,7 @@ static void normal_get_additional_char(NormalState *s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lang) {
|
||||||
// When getting a text character and the next character is a
|
// When getting a text character and the next character is a
|
||||||
// multi-byte character, it could be a composing character.
|
// multi-byte character, it could be a composing character.
|
||||||
// However, don't wait for it to arrive. Also, do enable mapping,
|
// However, don't wait for it to arrive. Also, do enable mapping,
|
||||||
@@ -826,6 +827,12 @@ static void normal_get_additional_char(NormalState *s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
no_mapping++;
|
no_mapping++;
|
||||||
|
// Vim may be in a different mode when the user types the next key,
|
||||||
|
// but when replaying a recording the next key is already in the
|
||||||
|
// 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--;
|
||||||
allow_keys--;
|
allow_keys--;
|
||||||
|
@@ -758,8 +758,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')
|
||||||
@@ -779,7 +780,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')
|
||||||
@@ -797,5 +801,25 @@ 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
|
||||||
|
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Reference in New Issue
Block a user