diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-01-21 18:08:56 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-01-21 18:08:56 +0800 |
commit | ff7c3d12750b1cd4baccea0baeafe7e5d5339e94 (patch) | |
tree | 80f5d1aaf89e473e549982121ce14dfeaf3092bc | |
parent | c977d8b43cd6ecf7ad756f9b064eadea79fbd604 (diff) | |
download | rneovim-ff7c3d12750b1cd4baccea0baeafe7e5d5339e94.tar.gz rneovim-ff7c3d12750b1cd4baccea0baeafe7e5d5339e94.tar.bz2 rneovim-ff7c3d12750b1cd4baccea0baeafe7e5d5339e94.zip |
fix(input): never escape CSI bytes
-rw-r--r-- | src/nvim/getchar.c | 7 | ||||
-rw-r--r-- | src/nvim/os/input.c | 14 | ||||
-rw-r--r-- | test/functional/ui/input_spec.lua | 21 |
3 files changed, 28 insertions, 14 deletions
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 5565e17597..bddf2e21d2 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1010,12 +1010,11 @@ void ins_char_typebuf(int c) 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; + if ((uint8_t)(*p) == K_SPECIAL) { 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; + *p++ = KS_SPECIAL; + *p++ = KE_FILLER; } else { p++; } diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 3790eba212..54cfaee80a 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -234,9 +234,9 @@ size_t input_enqueue(String keys) while (rbuffer_space(input_buffer) >= 19 && ptr < end) { // A "<x>" form occupies at least 1 characters, and produces up // to 19 characters (1 + 5 * 3 for the char and 3 for a modifier). - // In the case of K_SPECIAL(0x80) or CSI(0x9B), 3 bytes are escaped and - // needed, but since the keys are UTF-8, so the first byte cannot be - // K_SPECIAL(0x80) or CSI(0x9B). + // In the case of K_SPECIAL(0x80), 3 bytes are escaped and needed, + // but since the keys are UTF-8, so the first byte cannot be + // K_SPECIAL(0x80). uint8_t buf[19] = { 0 }; unsigned int new_size = trans_special((const uint8_t **)&ptr, (size_t)(end - ptr), buf, true, @@ -263,12 +263,8 @@ size_t input_enqueue(String keys) continue; } - // copy the character, escaping CSI and K_SPECIAL - if ((uint8_t)*ptr == CSI) { - rbuffer_write(input_buffer, (char *)&(uint8_t){ K_SPECIAL }, 1); - rbuffer_write(input_buffer, (char *)&(uint8_t){ KS_EXTRA }, 1); - rbuffer_write(input_buffer, (char *)&(uint8_t){ KE_CSI }, 1); - } else if ((uint8_t)*ptr == K_SPECIAL) { + // copy the character, escaping K_SPECIAL + if ((uint8_t)(*ptr) == K_SPECIAL) { rbuffer_write(input_buffer, (char *)&(uint8_t){ K_SPECIAL }, 1); rbuffer_write(input_buffer, (char *)&(uint8_t){ KS_SPECIAL }, 1); rbuffer_write(input_buffer, (char *)&(uint8_t){ KE_FILLER }, 1); diff --git a/test/functional/ui/input_spec.lua b/test/functional/ui/input_spec.lua index ea8968a653..11718a6e18 100644 --- a/test/functional/ui/input_spec.lua +++ b/test/functional/ui/input_spec.lua @@ -114,11 +114,30 @@ describe('mappings', function() end) end) -describe('input utf sequences that contain CSI/K_SPECIAL', function() +describe('input utf sequences that contain K_SPECIAL (0x80)', function() it('ok', function() feed('i…<esc>') expect('…') end) + + it('can be mapped', function() + command('inoremap … E280A6') + feed('i…<esc>') + expect('E280A6') + end) +end) + +describe('input utf sequences that contain CSI (0x9B)', function() + it('ok', function() + feed('iě<esc>') + expect('ě') + end) + + it('can be mapped', function() + command('inoremap ě C49B') + feed('iě<esc>') + expect('C49B') + end) end) describe('input non-printable chars', function() |