mirror of https://github.com/folke/lazy.nvim.git
fix(keys): properly re-create buffer-local mappings. Fixes #1448
This commit is contained in:
parent
0de782a6b0
commit
39de11a2fa
|
@ -123,11 +123,6 @@ function M:_add(keys)
|
||||||
Util.track()
|
Util.track()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Create the real buffer-local mapping
|
|
||||||
if keys.ft then
|
|
||||||
self:_set(keys, buf)
|
|
||||||
end
|
|
||||||
|
|
||||||
if keys.mode:sub(-1) == "a" then
|
if keys.mode:sub(-1) == "a" then
|
||||||
lhs = lhs .. "<C-]>"
|
lhs = lhs .. "<C-]>"
|
||||||
end
|
end
|
||||||
|
@ -162,19 +157,21 @@ function M:_add(keys)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Delete a mapping and create the real global
|
-- Delete a mapping and create the real global/buffer-local
|
||||||
-- mapping when needed
|
-- mapping when needed
|
||||||
---@param keys LazyKeys
|
---@param keys LazyKeys
|
||||||
function M:_del(keys)
|
function M:_del(keys)
|
||||||
pcall(vim.keymap.del, keys.mode, keys.lhs, {
|
-- bufs will be all buffers of the filetype for a buffer-local mapping
|
||||||
-- NOTE: for buffer-local mappings, we only delete the mapping for the current buffer
|
-- OR `false` for a global mapping
|
||||||
-- So the mapping could still exist in other buffers
|
local bufs = keys.ft
|
||||||
buffer = keys.ft and true or nil,
|
and vim.tbl_filter(function(buf)
|
||||||
})
|
return vim.bo[buf].filetype == keys.ft
|
||||||
-- make sure to create global mappings when needed
|
end, vim.api.nvim_list_bufs())
|
||||||
-- buffer-local mappings are managed by lazy
|
or { false }
|
||||||
if not keys.ft then
|
|
||||||
self:_set(keys)
|
for _, buf in ipairs(bufs) do
|
||||||
|
pcall(vim.keymap.del, keys.mode, keys.lhs, { buffer = buf or nil })
|
||||||
|
self:_set(keys, buf or nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue