mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 11:15:14 -07:00
input: Escape utf8 sequences that contain CSI/K_SPECIAL
This commit is contained in:
parent
25ceadab37
commit
e7c945ab59
@ -148,22 +148,34 @@ size_t input_enqueue(String keys)
|
|||||||
uint8_t buf[6] = {0};
|
uint8_t buf[6] = {0};
|
||||||
unsigned int new_size = trans_special((uint8_t **)&ptr, buf, true);
|
unsigned int new_size = trans_special((uint8_t **)&ptr, buf, true);
|
||||||
|
|
||||||
if (!new_size) {
|
if (new_size) {
|
||||||
if (*ptr == '<') {
|
new_size = handle_mouse_event(&ptr, buf, new_size);
|
||||||
// Invalid key sequence, skip until the next '>' or until *end
|
rbuffer_write(input_buffer, (char *)buf, new_size);
|
||||||
do {
|
continue;
|
||||||
ptr++;
|
|
||||||
} while (ptr < end && *ptr != '>');
|
|
||||||
ptr++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// copy the character unmodified
|
|
||||||
*buf = (uint8_t)*ptr++;
|
|
||||||
new_size = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
new_size = handle_mouse_event(&ptr, buf, new_size);
|
if (*ptr == '<') {
|
||||||
rbuffer_write(input_buffer, (char *)buf, new_size);
|
// Invalid key sequence, skip until the next '>' or until *end
|
||||||
|
do {
|
||||||
|
ptr++;
|
||||||
|
} while (ptr < end && *ptr != '>');
|
||||||
|
ptr++;
|
||||||
|
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) {
|
||||||
|
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);
|
size_t rv = (size_t)(ptr - keys.data);
|
||||||
|
@ -16,7 +16,7 @@ describe('mapping', function()
|
|||||||
|
|
||||||
-- Abbreviations with р (0x80) should work.
|
-- Abbreviations with р (0x80) should work.
|
||||||
execute('inoreab чкпр vim')
|
execute('inoreab чкпр vim')
|
||||||
feed('GAчкпр <cr><esc>')
|
feed('GAчкпр <esc>')
|
||||||
|
|
||||||
-- langmap should not get remapped in insert mode.
|
-- langmap should not get remapped in insert mode.
|
||||||
execute('inoremap { FAIL_ilangmap')
|
execute('inoremap { FAIL_ilangmap')
|
||||||
@ -27,10 +27,11 @@ describe('mapping', function()
|
|||||||
execute('inoremap <expr> { "FAIL_iexplangmap"')
|
execute('inoremap <expr> { "FAIL_iexplangmap"')
|
||||||
feed('o+<esc>')
|
feed('o+<esc>')
|
||||||
|
|
||||||
|
|
||||||
-- Assert buffer contents.
|
-- Assert buffer contents.
|
||||||
expect([[
|
expect([[
|
||||||
test starts here:
|
test starts here:
|
||||||
vim
|
vim
|
||||||
+
|
+
|
||||||
+]])
|
+]])
|
||||||
end)
|
end)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
local helpers = require('test.functional.helpers')
|
local helpers = require('test.functional.helpers')
|
||||||
local clear, execute, nvim = helpers.clear, helpers.execute, helpers.nvim
|
local clear, execute, nvim = helpers.clear, helpers.execute, helpers.nvim
|
||||||
local feed, next_message, eq = helpers.feed, helpers.next_message, helpers.eq
|
local feed, next_message, eq = helpers.feed, helpers.next_message, helpers.eq
|
||||||
|
local expect = helpers.expect
|
||||||
|
|
||||||
describe('mappings', function()
|
describe('mappings', function()
|
||||||
local cid
|
local cid
|
||||||
@ -38,3 +39,10 @@ describe('mappings', function()
|
|||||||
check_mapping('<a-s-c-up>', '<c-s-a-up>')
|
check_mapping('<a-s-c-up>', '<c-s-a-up>')
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('input utf sequences that contain CSI/K_SPECIAL', function()
|
||||||
|
it('ok', function()
|
||||||
|
feed('i…<esc>')
|
||||||
|
expect('…')
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user