mirror of
https://github.com/neovim/neovim.git
synced 2025-01-02 17:33:28 -07:00
fix(input): never escape CSI bytes
This commit is contained in:
parent
c977d8b43c
commit
ff7c3d1275
@ -1010,12 +1010,11 @@ void ins_char_typebuf(int c)
|
|||||||
buf[utf_char2bytes(c, buf)] = NUL;
|
buf[utf_char2bytes(c, buf)] = NUL;
|
||||||
char_u *p = buf;
|
char_u *p = buf;
|
||||||
while (*p) {
|
while (*p) {
|
||||||
if ((uint8_t)(*p) == CSI || (uint8_t)(*p) == K_SPECIAL) {
|
if ((uint8_t)(*p) == K_SPECIAL) {
|
||||||
bool is_csi = (uint8_t)(*p) == CSI;
|
|
||||||
memmove(p + 3, p + 1, STRLEN(p + 1) + 1);
|
memmove(p + 3, p + 1, STRLEN(p + 1) + 1);
|
||||||
*p++ = K_SPECIAL;
|
*p++ = K_SPECIAL;
|
||||||
*p++ = is_csi ? KS_EXTRA : KS_SPECIAL;
|
*p++ = KS_SPECIAL;
|
||||||
*p++ = is_csi ? KE_CSI : KE_FILLER;
|
*p++ = KE_FILLER;
|
||||||
} else {
|
} else {
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
@ -234,9 +234,9 @@ size_t input_enqueue(String keys)
|
|||||||
while (rbuffer_space(input_buffer) >= 19 && ptr < end) {
|
while (rbuffer_space(input_buffer) >= 19 && ptr < end) {
|
||||||
// A "<x>" form occupies at least 1 characters, and produces up
|
// 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).
|
// 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
|
// In the case of K_SPECIAL(0x80), 3 bytes are escaped and needed,
|
||||||
// needed, but since the keys are UTF-8, so the first byte cannot be
|
// but since the keys are UTF-8, so the first byte cannot be
|
||||||
// K_SPECIAL(0x80) or CSI(0x9B).
|
// K_SPECIAL(0x80).
|
||||||
uint8_t buf[19] = { 0 };
|
uint8_t buf[19] = { 0 };
|
||||||
unsigned int new_size
|
unsigned int new_size
|
||||||
= trans_special((const uint8_t **)&ptr, (size_t)(end - ptr), buf, true,
|
= trans_special((const uint8_t **)&ptr, (size_t)(end - ptr), buf, true,
|
||||||
@ -263,12 +263,8 @@ size_t input_enqueue(String keys)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy the character, escaping CSI and K_SPECIAL
|
// copy the character, escaping K_SPECIAL
|
||||||
if ((uint8_t)*ptr == CSI) {
|
if ((uint8_t)(*ptr) == K_SPECIAL) {
|
||||||
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){ K_SPECIAL }, 1);
|
||||||
rbuffer_write(input_buffer, (char *)&(uint8_t){ KS_SPECIAL }, 1);
|
rbuffer_write(input_buffer, (char *)&(uint8_t){ KS_SPECIAL }, 1);
|
||||||
rbuffer_write(input_buffer, (char *)&(uint8_t){ KE_FILLER }, 1);
|
rbuffer_write(input_buffer, (char *)&(uint8_t){ KE_FILLER }, 1);
|
||||||
|
@ -114,11 +114,30 @@ describe('mappings', function()
|
|||||||
end)
|
end)
|
||||||
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()
|
it('ok', function()
|
||||||
feed('i…<esc>')
|
feed('i…<esc>')
|
||||||
expect('…')
|
expect('…')
|
||||||
end)
|
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)
|
end)
|
||||||
|
|
||||||
describe('input non-printable chars', function()
|
describe('input non-printable chars', function()
|
||||||
|
Loading…
Reference in New Issue
Block a user