Skip to content

Commit 3ea8f8c

Browse files
committed
fix: missing buffer-based keymap registrations
1 parent 8b9af0c commit 3ea8f8c

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

lua/copilot/keymaps/init.lua

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ local previous_keymaps = {}
88
---@param key string
99
---@param action function
1010
---@param desc string
11-
function M.register_keymap(mode, key, action, desc)
11+
---@param bufnr integer
12+
function M.register_keymap(mode, key, action, desc, bufnr)
1213
if not key then
1314
return
1415
end
1516

1617
if not mode or not action then
17-
logger.error("Invalid parameters to register_keymap" .. vim.inspect({ mode, key, action, desc }))
18+
logger.error("Invalid parameters to register_keymap" .. vim.inspect({ mode, key, action, desc, bufnr }))
1819
return
1920
end
2021

@@ -23,6 +24,7 @@ function M.register_keymap(mode, key, action, desc)
2324
end, {
2425
desc = desc,
2526
silent = true,
27+
buffer = bufnr,
2628
})
2729
end
2830

@@ -99,14 +101,15 @@ function M.unset_keymap_if_exists(mode, key, bufnr)
99101
return
100102
end
101103

102-
local ok, err = pcall(vim.api.nvim_del_buf_keymap, bufnr, mode, key)
104+
local ok, err = pcall(vim.api.nvim_buf_del_keymap, bufnr, mode, key)
103105

104106
if not ok then
105107
local suggestion_keymaps = config.suggestion.keymap or {}
108+
local nes_keymaps = config.nes.keymap or {}
106109
local panel_keymaps = config.panel.keymap or {}
107110
local found = false
108111

109-
for _, tbl in ipairs({ suggestion_keymaps, panel_keymaps }) do
112+
for _, tbl in ipairs({ suggestion_keymaps, nes_keymaps, panel_keymaps }) do
110113
for _, v in pairs(tbl) do
111114
if v == key then
112115
if found then
@@ -119,7 +122,7 @@ function M.unset_keymap_if_exists(mode, key, bufnr)
119122
end
120123
end
121124

122-
logger.error("Could not unset keymap for " .. mode .. " " .. key .. ": " .. err)
125+
logger.error("Could not unset keymap for " .. mode .. " " .. key .. ", bufnr " .. bufnr .. ": " .. err)
123126
end
124127
end
125128

tests/test_keymaps.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ T["keymaps()"]["passthrough Esc - base test setting highlight"] = function()
2121
child.lua([[
2222
require("copilot.keymaps").register_keymap_with_passthrough("n", "<Esc>", function()
2323
return true
24-
end, "Passthrough Esc")
24+
end, "Passthrough Esc", vim.api.nvim_get_current_buf())
2525
]])
2626
child.type_keys("i123", "<Esc>", "o456", "<Esc>")
2727
child.type_keys("/123", "<CR>")
@@ -37,7 +37,7 @@ T["keymaps()"]["passthrough Esc with func - return false, will remove hl"] = fun
3737
child.lua([[
3838
require("copilot.keymaps").register_keymap_with_passthrough("n", "<esc>", function()
3939
return false
40-
end, "Passthrough Esc")
40+
end, "Passthrough Esc", vim.api.nvim_get_current_buf())
4141
]])
4242
child.type_keys("i123", "<Esc>", "o456", "<Esc>")
4343
child.type_keys("/123", "<CR>")
@@ -50,9 +50,9 @@ T["keymaps()"]["passthrough Esc - return false, will remove hl"] = function()
5050
child.o.lines, child.o.columns = 10, 15
5151
child.lua([[vim.keymap.set("n", "<Esc>", "<cmd>noh<CR>", { desc = "general clear highlights" })]])
5252
child.lua([[
53-
require("copilot.keymaps").register_keymap_with_passthrough("n", "<Esc>", function()
53+
require("copilot.keymaps").register_keymap_with_passthrough("n", "<esc>", function()
5454
return false
55-
end, "Passthrough Esc")
55+
end, "Passthrough Esc", vim.api.nvim_get_current_buf())
5656
]])
5757
child.type_keys("i123", "<Esc>", "o456", "<Esc>")
5858
child.type_keys("/123", "<CR>")
@@ -67,7 +67,7 @@ T["keymaps()"]["passthrough Esc - return true, will not remove hl"] = function()
6767
child.lua([[
6868
require("copilot.keymaps").register_keymap_with_passthrough("n", "<Esc>", function()
6969
return true
70-
end, "Passthrough Esc")
70+
end, "Passthrough Esc", vim.api.nvim_get_current_buf())
7171
]])
7272
child.type_keys("i123", "<Esc>", "o456", "<Esc>")
7373
child.type_keys("/123", "<CR>")

0 commit comments

Comments
 (0)