Skip to content

Commit 736b88c

Browse files
noib3AntoineGS
authored andcommitted
fix(keymaps): preserve special insert keys in passthrough fallback
This fixes insert-mode fallbacks like `<Right>` being inserted as literal bytes.
1 parent 07aa571 commit 736b88c

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

lua/copilot/keymaps/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,11 @@ function M.register_keymap_with_passthrough(mode, key, action, desc, bufnr)
119119
end
120120

121121
logger.trace("No previous keymap to pass through for " .. keymap_key)
122-
return vim.api.nvim_replace_termcodes(key, true, false, true)
122+
return key
123123
end, {
124124
desc = desc,
125125
expr = true,
126+
replace_keycodes = true,
126127
silent = true,
127128
buffer = bufnr,
128129
})

tests/test_keymaps.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,16 @@ T["keymaps()"]["passthrough Tab - return false inserts tab character"] = functio
8888
MiniTest.expect.equality(line, "hello\tworld")
8989
end
9090

91+
T["keymaps()"]["passthrough Right - return false moves cursor right"] = function()
92+
child.lua([[
93+
require("copilot.keymaps").register_keymap_with_passthrough("i", "<Right>", function()
94+
return false
95+
end, "Passthrough Right", vim.api.nvim_get_current_buf())
96+
]])
97+
child.type_keys("i", "abcd", "<Esc>", "0i", "<Right>", "X", "<Esc>")
98+
99+
local line = child.lua("return vim.api.nvim_get_current_line()")
100+
MiniTest.expect.equality(line, "aXbcd")
101+
end
102+
91103
return T

0 commit comments

Comments
 (0)