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) {
|
||||
|
@ -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;
|
||||
|
@ -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