mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 18:55:14 -07:00
fix(input): resolve isolated (non-ALT/META) mappings #13109
Problem:
Since 2f06413dfb
#13042, "ESC+c" sequence is treated as "ESC c"
instead of "M-c" (ALT/META+c) when not mapped, aka "fallthrough"
behavior. But "isolated" (non-ALT/META) mappings to ESC and c were not
resolved. This behavior is especially confusing for the TUI.
Solution:
Resolve isolated ESC, c mappings when there is no M-c mapping.
Change ins_char_typebuf() to escape CSI, K_SPECIAL.
fixes #13086
fixes #15869
This commit is contained in:
parent
79fb9ed080
commit
c4857b695f
@ -1000,6 +1000,18 @@ void ins_char_typebuf(int c)
|
|||||||
buf[3] = NUL;
|
buf[3] = NUL;
|
||||||
} else {
|
} else {
|
||||||
buf[utf_char2bytes(c, buf)] = NUL;
|
buf[utf_char2bytes(c, buf)] = NUL;
|
||||||
|
char_u *p = buf;
|
||||||
|
while (*p) {
|
||||||
|
if ((uint8_t)(*p) == CSI || (uint8_t)(*p) == K_SPECIAL) {
|
||||||
|
bool is_csi = (uint8_t)(*p) == CSI;
|
||||||
|
memmove(p + 3, p + 1, STRLEN(p + 1) + 1);
|
||||||
|
*p++ = K_SPECIAL;
|
||||||
|
*p++ = is_csi ? KS_EXTRA : KS_SPECIAL;
|
||||||
|
*p++ = is_csi ? KE_CSI : KE_FILLER;
|
||||||
|
} else {
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(void)ins_typebuf(buf, KeyNoremap, 0, !KeyTyped, cmd_silent);
|
(void)ins_typebuf(buf, KeyNoremap, 0, !KeyTyped, cmd_silent);
|
||||||
}
|
}
|
||||||
@ -1573,9 +1585,9 @@ int vgetc(void)
|
|||||||
if (!no_mapping && KeyTyped
|
if (!no_mapping && KeyTyped
|
||||||
&& (mod_mask == MOD_MASK_ALT || mod_mask == MOD_MASK_META)) {
|
&& (mod_mask == MOD_MASK_ALT || mod_mask == MOD_MASK_META)) {
|
||||||
mod_mask = 0;
|
mod_mask = 0;
|
||||||
stuffcharReadbuff(c);
|
ins_char_typebuf(c);
|
||||||
u_sync(false);
|
ins_char_typebuf(ESC);
|
||||||
c = ESC;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -11,15 +11,20 @@ describe('meta-keys #8226 #13042', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('ALT/META, normal-mode', function()
|
it('ALT/META, normal-mode', function()
|
||||||
-- Unmapped ALT-chords behave as ESC+c
|
-- Unmapped ALT-chord behaves as ESC+c.
|
||||||
insert('hello')
|
insert('hello')
|
||||||
feed('0<A-x><M-x>')
|
feed('0<A-x><M-x>')
|
||||||
expect('llo')
|
expect('llo')
|
||||||
|
-- Unmapped ALT-chord resolves isolated (non-ALT) ESC mapping. #13086 #15869
|
||||||
|
command('nnoremap <ESC> A<lt>ESC><Esc>')
|
||||||
|
command('nnoremap ; A;<Esc>')
|
||||||
|
feed('<A-;><M-;>')
|
||||||
|
expect('llo<ESC>;<ESC>;')
|
||||||
-- Mapped ALT-chord behaves as mapped.
|
-- Mapped ALT-chord behaves as mapped.
|
||||||
command('nnoremap <M-l> Ameta-l<Esc>')
|
command('nnoremap <M-l> Ameta-l<Esc>')
|
||||||
command('nnoremap <A-j> Aalt-j<Esc>')
|
command('nnoremap <A-j> Aalt-j<Esc>')
|
||||||
feed('<A-j><M-l>')
|
feed('<A-j><M-l>')
|
||||||
expect('lloalt-jmeta-l')
|
expect('llo<ESC>;<ESC>;alt-jmeta-l')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('ALT/META, visual-mode', function()
|
it('ALT/META, visual-mode', function()
|
||||||
@ -27,11 +32,15 @@ describe('meta-keys #8226 #13042', function()
|
|||||||
insert('peaches')
|
insert('peaches')
|
||||||
feed('viw<A-x>viw<M-x>')
|
feed('viw<A-x>viw<M-x>')
|
||||||
expect('peach')
|
expect('peach')
|
||||||
|
-- Unmapped ALT-chord resolves isolated (non-ALT) ESC mapping. #13086 #15869
|
||||||
|
command('vnoremap <ESC> A<lt>ESC>')
|
||||||
|
feed('viw<A-;><ESC>viw<M-;><ESC>')
|
||||||
|
expect('peach<ESC>;<ESC>;')
|
||||||
-- Mapped ALT-chord behaves as mapped.
|
-- Mapped ALT-chord behaves as mapped.
|
||||||
command('vnoremap <M-l> Ameta-l<Esc>')
|
command('vnoremap <M-l> Ameta-l<Esc>')
|
||||||
command('vnoremap <A-j> Aalt-j<Esc>')
|
command('vnoremap <A-j> Aalt-j<Esc>')
|
||||||
feed('viw<A-j>viw<M-l>')
|
feed('viw<A-j>viw<M-l>')
|
||||||
expect('peachalt-jmeta-l')
|
expect('peach<ESC>;<ESC>;alt-jmeta-l')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('ALT/META insert-mode', function()
|
it('ALT/META insert-mode', function()
|
||||||
|
Loading…
Reference in New Issue
Block a user