diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index beb4ff4da6..16ad890360 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1000,6 +1000,18 @@ void ins_char_typebuf(int c) buf[3] = NUL; } else { 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); } @@ -1573,9 +1585,9 @@ int vgetc(void) if (!no_mapping && KeyTyped && (mod_mask == MOD_MASK_ALT || mod_mask == MOD_MASK_META)) { mod_mask = 0; - stuffcharReadbuff(c); - u_sync(false); - c = ESC; + ins_char_typebuf(c); + ins_char_typebuf(ESC); + continue; } break; diff --git a/test/functional/editor/meta_key_spec.lua b/test/functional/editor/meta_key_spec.lua index 2a9541ba96..c219204409 100644 --- a/test/functional/editor/meta_key_spec.lua +++ b/test/functional/editor/meta_key_spec.lua @@ -11,15 +11,20 @@ describe('meta-keys #8226 #13042', function() end) it('ALT/META, normal-mode', function() - -- Unmapped ALT-chords behave as ESC+c + -- Unmapped ALT-chord behaves as ESC+c. insert('hello') feed('0') expect('llo') + -- Unmapped ALT-chord resolves isolated (non-ALT) ESC mapping. #13086 #15869 + command('nnoremap AESC>') + command('nnoremap ; A;') + feed('') + expect('llo;;') -- Mapped ALT-chord behaves as mapped. command('nnoremap Ameta-l') command('nnoremap Aalt-j') feed('') - expect('lloalt-jmeta-l') + expect('llo;;alt-jmeta-l') end) it('ALT/META, visual-mode', function() @@ -27,11 +32,15 @@ describe('meta-keys #8226 #13042', function() insert('peaches') feed('viwviw') expect('peach') + -- Unmapped ALT-chord resolves isolated (non-ALT) ESC mapping. #13086 #15869 + command('vnoremap AESC>') + feed('viwviw') + expect('peach;;') -- Mapped ALT-chord behaves as mapped. command('vnoremap Ameta-l') command('vnoremap Aalt-j') feed('viwviw') - expect('peachalt-jmeta-l') + expect('peach;;alt-jmeta-l') end) it('ALT/META insert-mode', function()