fix(input): discard following keys when discarding <Cmd>/K_LUA (#36498)

Technically the current behavior does match documentation. However, the
keys following <Cmd>/K_LUA aren't normally received by vim.on_key()
callbacks either, so it does makes sense to discard them along with the
preceding key.

One may also argue that vim.on_key() callbacks should instead receive
the following keys together with the <Cmd>/K_LUA, but doing that may
cause some performance problems, and even in that case the keys should
still be discarded together.
This commit is contained in:
zeertzjq
2025-11-20 12:33:02 +08:00
committed by GitHub
parent 3b6df3ae55
commit a04c73cc17
8 changed files with 112 additions and 16 deletions

View File

@@ -1383,8 +1383,10 @@ vim.on_key({fn}, {ns_id}, {opts}) *vim.on_key()*
applied. {typed} may be empty if {key} is produced by
non-typed key(s) or by the same typed key(s) that produced a
previous {key}. If {fn} returns an empty string, {key} is
discarded/ignored. When {fn} is `nil`, the callback
associated with namespace {ns_id} is removed.
discarded/ignored, and if {key} is <Cmd> then the
"<Cmd>…<CR>" sequence is discarded as a whole. When {fn} is
`nil`, the callback associated with namespace {ns_id} is
removed.
• {ns_id} (`integer?`) Namespace ID. If nil or 0, generates and returns
a new |nvim_create_namespace()| id.
• {opts} (`table?`) Optional parameters

View File

@@ -604,7 +604,8 @@ local on_key_cbs = {} --- @type table<integer,[function, table]>
--- are applied, and {typed} is the key(s) before mappings are applied.
--- {typed} may be empty if {key} is produced by non-typed key(s) or by the
--- same typed key(s) that produced a previous {key}.
--- If {fn} returns an empty string, {key} is discarded/ignored.
--- If {fn} returns an empty string, {key} is discarded/ignored, and if {key}
--- is [<Cmd>] then the "[<Cmd>]…[<CR>]" sequence is discarded as a whole.
--- When {fn} is `nil`, the callback associated with namespace {ns_id} is removed.
---@param ns_id integer? Namespace ID. If nil or 0, generates and returns a
--- new |nvim_create_namespace()| id.