mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
test: add a bit more testing for vim.on_key() (#28095)
Also: - Don't use NUMBUFLEN as buffer length as its unrelated. - Restore accidentally removed comment from last commit.
This commit is contained in:
parent
fc19ee01ac
commit
f29c41d665
@ -1122,6 +1122,8 @@ static void gotchars(const uint8_t *chars, size_t len)
|
||||
pending--;
|
||||
}
|
||||
|
||||
// When receiving a special key sequence, store it until we have all
|
||||
// the bytes and we can decide what to do with it.
|
||||
if ((pending == 0 || in_mbyte) && c == K_SPECIAL) {
|
||||
pending += 2;
|
||||
if (!in_mbyte) {
|
||||
|
@ -1914,7 +1914,7 @@ static void set_hl_attr(int idx)
|
||||
at_en.cterm_bg_color = (int16_t)sgp->sg_cterm_bg;
|
||||
at_en.rgb_ae_attr = (int16_t)sgp->sg_gui;
|
||||
// FIXME(tarruda): The "unset value" for rgb is -1, but since hlgroup is
|
||||
// initialized with 0(by garray functions), check for sg_rgb_{f,b}g_name
|
||||
// initialized with 0 (by garray functions), check for sg_rgb_{f,b}g_name
|
||||
// before setting attr_entry->{f,g}g_color to a other than -1
|
||||
at_en.rgb_fg_color = sgp->sg_rgb_fg_idx != kColorIdxNone ? sgp->sg_rgb_fg : -1;
|
||||
at_en.rgb_bg_color = sgp->sg_rgb_bg_idx != kColorIdxNone ? sgp->sg_rgb_bg : -1;
|
||||
|
@ -2066,7 +2066,7 @@ char *nlua_register_table_as_callable(const typval_T *const arg)
|
||||
|
||||
void nlua_execute_on_key(int c)
|
||||
{
|
||||
char buf[NUMBUFLEN];
|
||||
char buf[MB_MAXBYTES * 3 + 4];
|
||||
size_t buf_len = special_to_buf(c, mod_mask, false, buf);
|
||||
|
||||
lua_State *const lstate = global_lstate;
|
||||
|
@ -255,9 +255,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), 3 bytes are escaped and needed,
|
||||
// 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).
|
||||
// K_SPECIAL (0x80).
|
||||
uint8_t buf[19] = { 0 };
|
||||
// Do not simplify the keys here. Simplification will be done later.
|
||||
unsigned new_size
|
||||
|
@ -3007,7 +3007,7 @@ describe('lua stdlib', function()
|
||||
end)
|
||||
|
||||
describe('vim.on_key', function()
|
||||
it('tracks keystrokes', function()
|
||||
it('tracks Unicode input', function()
|
||||
insert([[hello world ]])
|
||||
|
||||
exec_lua [[
|
||||
@ -3022,10 +3022,24 @@ describe('lua stdlib', function()
|
||||
end)
|
||||
]]
|
||||
|
||||
insert([[next 🤦 lines å ]])
|
||||
insert([[next 🤦 lines å …]])
|
||||
|
||||
-- It has escape in the keys pressed
|
||||
eq('inext 🤦 lines å <ESC>', exec_lua [[return table.concat(keys, '')]])
|
||||
eq('inext 🤦 lines å …<ESC>', exec_lua [[return table.concat(keys, '')]])
|
||||
end)
|
||||
|
||||
it('tracks input with modifiers', function()
|
||||
exec_lua [[
|
||||
keys = {}
|
||||
|
||||
vim.on_key(function(buf)
|
||||
table.insert(keys, vim.fn.keytrans(buf))
|
||||
end)
|
||||
]]
|
||||
|
||||
feed([[i<C-V><C-;><C-V><C-…><Esc>]])
|
||||
|
||||
eq('i<C-V><C-;><C-V><C-…><Esc>', exec_lua [[return table.concat(keys, '')]])
|
||||
end)
|
||||
|
||||
it('allows removing on_key listeners', function()
|
||||
|
Loading…
Reference in New Issue
Block a user