mirror of
https://github.com/neovim/neovim.git
synced 2025-09-08 12:28:18 +00:00
fix(lua): clear got_int when calling vim.on_key() callback (#18979)
This commit is contained in:
@@ -1775,10 +1775,13 @@ void nlua_execute_on_key(int c)
|
|||||||
// [ vim, vim._on_key, buf ]
|
// [ vim, vim._on_key, buf ]
|
||||||
lua_pushlstring(lstate, (const char *)buf, buf_len);
|
lua_pushlstring(lstate, (const char *)buf, buf_len);
|
||||||
|
|
||||||
|
int save_got_int = got_int;
|
||||||
|
got_int = false; // avoid interrupts when the key typed is Ctrl-C
|
||||||
if (nlua_pcall(lstate, 1, 0)) {
|
if (nlua_pcall(lstate, 1, 0)) {
|
||||||
nlua_error(lstate,
|
nlua_error(lstate,
|
||||||
_("Error executing vim.on_key Lua callback: %.*s"));
|
_("Error executing vim.on_key Lua callback: %.*s"));
|
||||||
}
|
}
|
||||||
|
got_int |= save_got_int;
|
||||||
|
|
||||||
// [ vim ]
|
// [ vim ]
|
||||||
lua_pop(lstate, 1);
|
lua_pop(lstate, 1);
|
||||||
|
@@ -23,6 +23,7 @@ local mkdir_p = helpers.mkdir_p
|
|||||||
local rmdir = helpers.rmdir
|
local rmdir = helpers.rmdir
|
||||||
local write_file = helpers.write_file
|
local write_file = helpers.write_file
|
||||||
local expect_exit = helpers.expect_exit
|
local expect_exit = helpers.expect_exit
|
||||||
|
local poke_eventloop = helpers.poke_eventloop
|
||||||
|
|
||||||
describe('lua stdlib', function()
|
describe('lua stdlib', function()
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
@@ -2268,6 +2269,22 @@ describe('lua stdlib', function()
|
|||||||
|
|
||||||
eq('iworld<ESC>', exec_lua[[return table.concat(keys, '')]])
|
eq('iworld<ESC>', exec_lua[[return table.concat(keys, '')]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('can call vim.fn functions on Ctrl-C #17273', function()
|
||||||
|
exec_lua([[
|
||||||
|
_G.ctrl_c_cmdtype = ''
|
||||||
|
|
||||||
|
vim.on_key(function(c)
|
||||||
|
if c == '\3' then
|
||||||
|
_G.ctrl_c_cmdtype = vim.fn.getcmdtype()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
]])
|
||||||
|
feed('/')
|
||||||
|
poke_eventloop() -- This is needed because Ctrl-C flushes input
|
||||||
|
feed('<C-C>')
|
||||||
|
eq('/', exec_lua([[return _G.ctrl_c_cmdtype]]))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('vim.wait', function()
|
describe('vim.wait', function()
|
||||||
|
Reference in New Issue
Block a user