diff options
-rw-r--r-- | src/nvim/os/input.c | 38 | ||||
-rw-r--r-- | test/functional/legacy/mapping_spec.lua | 5 | ||||
-rw-r--r-- | test/functional/ui/input_spec.lua | 8 |
3 files changed, 36 insertions, 15 deletions
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 2c2b0fc871..00efa28161 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -148,22 +148,34 @@ size_t input_enqueue(String keys) uint8_t buf[6] = {0}; unsigned int new_size = trans_special((uint8_t **)&ptr, buf, true); - if (!new_size) { - if (*ptr == '<') { - // Invalid key sequence, skip until the next '>' or until *end - do { - ptr++; - } while (ptr < end && *ptr != '>'); + if (new_size) { + new_size = handle_mouse_event(&ptr, buf, new_size); + rbuffer_write(input_buffer, (char *)buf, new_size); + continue; + } + + if (*ptr == '<') { + // Invalid key sequence, skip until the next '>' or until *end + do { ptr++; - continue; - } - // copy the character unmodified - *buf = (uint8_t)*ptr++; - new_size = 1; + } while (ptr < end && *ptr != '>'); + ptr++; + continue; } - new_size = handle_mouse_event(&ptr, buf, new_size); - rbuffer_write(input_buffer, (char *)buf, new_size); + // 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) { + 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); + } else { + rbuffer_write(input_buffer, ptr, 1); + } + ptr++; } size_t rv = (size_t)(ptr - keys.data); diff --git a/test/functional/legacy/mapping_spec.lua b/test/functional/legacy/mapping_spec.lua index 1451b268c5..c387d7484c 100644 --- a/test/functional/legacy/mapping_spec.lua +++ b/test/functional/legacy/mapping_spec.lua @@ -16,7 +16,7 @@ describe('mapping', function() -- Abbreviations with р (0x80) should work. execute('inoreab чкпр vim') - feed('GAчкпр <cr><esc>') + feed('GAчкпр <esc>') -- langmap should not get remapped in insert mode. execute('inoremap { FAIL_ilangmap') @@ -27,10 +27,11 @@ describe('mapping', function() execute('inoremap <expr> { "FAIL_iexplangmap"') feed('o+<esc>') + -- Assert buffer contents. expect([[ test starts here: - vim + vim + +]]) end) diff --git a/test/functional/ui/input_spec.lua b/test/functional/ui/input_spec.lua index 60a49c4ed7..81af908045 100644 --- a/test/functional/ui/input_spec.lua +++ b/test/functional/ui/input_spec.lua @@ -1,6 +1,7 @@ local helpers = require('test.functional.helpers') local clear, execute, nvim = helpers.clear, helpers.execute, helpers.nvim local feed, next_message, eq = helpers.feed, helpers.next_message, helpers.eq +local expect = helpers.expect describe('mappings', function() local cid @@ -38,3 +39,10 @@ describe('mappings', function() check_mapping('<a-s-c-up>', '<c-s-a-up>') end) end) + +describe('input utf sequences that contain CSI/K_SPECIAL', function() + it('ok', function() + feed('i…<esc>') + expect('…') + end) +end) |