Skip to content

Commit 555fe9d

Browse files
mwojickAntoineGS
authored andcommitted
fix: wrap maparg in nvim_buf_call to prevent capturing keymaps from the wrong buffer
1 parent f79864f commit 555fe9d

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

lua/copilot/keymaps/init.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ end
5050
---@param mode string
5151
---@param key string
5252
---@param keymap_key string
53-
local function save_existing_keymap(mode, key, keymap_key)
54-
local existing = vim.fn.maparg(key, mode, false, true)
53+
---@param bufnr integer
54+
local function save_existing_keymap(mode, key, keymap_key, bufnr)
55+
local existing
56+
vim.api.nvim_buf_call(bufnr, function()
57+
existing = vim.fn.maparg(key, mode, false, true)
58+
end)
5559

5660
if existing then
5761
if existing.rhs and existing.rhs ~= "" then
@@ -91,7 +95,7 @@ function M.register_keymap_with_passthrough(mode, key, action, desc, bufnr)
9195
logger.trace("Keymap already registered for " .. keymap_key)
9296
end
9397

94-
save_existing_keymap(mode, key, keymap_key)
98+
save_existing_keymap(mode, key, keymap_key, bufnr)
9599

96100
vim.keymap.set(mode, key, function()
97101
logger.trace("Keymap triggered for " .. keymap_key)

0 commit comments

Comments
 (0)