From 6b99fcb107c1436dfbb7e5cbb0c7072799973a11 Mon Sep 17 00:00:00 2001 From: yavorski <3436517+yavorski@users.noreply.github.com> Date: Wed, 13 May 2026 00:21:49 +0300 Subject: [PATCH] fix: preserve typeahead order on multi-key sequences The lazy-keys proxy used `nvim_feedkeys` with the `m` flag which appends to the typeahead buffer. For multi-key sequences like `vib`, the trailing `b` was already queued when the proxy fired on `i`, so appending `i` produced the order `b`, `i` instead of `i`, `b`. Result: pressing `vib` behave like `vb`. Switch to the `i` flag to insert at the front, matching lazy.nvim behavior (see lazy/core/handler/keys.lua:140). --- lua/zpack/lazy_trigger/keys.lua | 2 +- tests/lazy_keys_test.lua | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lua/zpack/lazy_trigger/keys.lua b/lua/zpack/lazy_trigger/keys.lua index e512471..bd9b7a7 100644 --- a/lua/zpack/lazy_trigger/keys.lua +++ b/lua/zpack/lazy_trigger/keys.lua @@ -53,7 +53,7 @@ M.setup = function(registered_pack_specs) for _, pack_spec in ipairs(key_info.pack_specs) do loader.process_spec(pack_spec) end - vim.api.nvim_feedkeys(vim.keycode(lhs), 'm', false) + vim.api.nvim_feedkeys(vim.keycode(lhs), 'i', false) end, { desc = key_spec.desc, mode = key_info.split_mode, diff --git a/tests/lazy_keys_test.lua b/tests/lazy_keys_test.lua index b4171df..cd875d5 100644 --- a/tests/lazy_keys_test.lua +++ b/tests/lazy_keys_test.lua @@ -703,5 +703,38 @@ return function() helpers.cleanup_test_env() end) + + -- Proxy must re-feed lhs at the FRONT of typeahead, not append. + -- Otherwise multi-key sequences like `vib` break and behave like `vb`. + helpers.test("Lazy proxy preserves typeahead order for multi-key sequences", function() + helpers.setup_test_env() + + local order = {} + vim.keymap.set('n', 'zb', function() table.insert(order, 'b') end) + + require('zpack').setup({ + spec = { + { + 'test/plugin', + keys = { { 'zi' } }, + config = function() + vim.keymap.set('n', 'zi', function() table.insert(order, 'i') end) + end, + }, + }, + defaults = { confirm = false }, + }) + + helpers.flush_pending() + vim.api.nvim_feedkeys('zizb', 'mx', false) + helpers.flush_pending() + + helpers.assert_equal(order[1], 'i', "re-fed `zi` must run before queued `zb`") + helpers.assert_equal(order[2], 'b', "queued `zb` must run after re-fed `zi`") + + pcall(vim.keymap.del, 'n', 'zi') + pcall(vim.keymap.del, 'n', 'zb') + helpers.cleanup_test_env() + end) end) end