fix(ui2): ui2 misinterprets getchar() input as pager_char (CR) #41465

Problem:
`vim.on_key()` callbacks are invoked for keys that `getchar()` consumes,
which never reach the main loop, and there is no way to tell such a key
apart.  With ui2 the `on_key` handler activated after interactive
cmdline, handles it as `pager_char` (thus enters the ui2 pager).

Solution:
Skip `vim.on_key()` callbacks during `getchar()`/`getcharstr()`.
This commit is contained in:
Justin M. Keyes
2026-08-24 10:18:47 -04:00
committed by GitHub
parent 143bbfbb12
commit 8c440c469b
6 changed files with 38 additions and 18 deletions

View File

@@ -2102,7 +2102,7 @@ describe('lua stdlib', function()
eq('/', exec_lua([[return _G.ctrl_c_cmdtype]]))
end)
it('callback is not invoked recursively #30752', function()
it('not invoked recursively #30752', function()
local screen = Screen.new(60, 10)
exec_lua([[
vim.on_key(function(key, typed)
@@ -2140,6 +2140,21 @@ describe('lua stdlib', function()
]])
end)
it('not invoked for keys consumed by getchar() #40010', function()
exec_lua(function()
_G.typed = {}
vim.on_key(function(_, typed)
table.insert(_G.typed, vim.fn.keytrans(typed))
end)
vim.keymap.set('n', '<M-m>', function()
_G.got = vim.fn.getchar()
end)
end)
feed('<M-m><CR>')
eq(13, exec_lua('return _G.got'))
eq({ '<M-m>' }, exec_lua('return _G.typed'))
end)
it('can discard input', function()
-- discard the first key produced by every other 'x' key typed
exec_lua [[