fix(keys): buffer-local nop mappings

This commit is contained in:
Folke Lemaitre 2024-06-06 10:15:33 +02:00
parent 0c1ec520af
commit ff90417808
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 7 additions and 2 deletions

View File

@ -102,6 +102,11 @@ function M.opts(keys)
return opts
end
---@param keys LazyKeys
function M.is_nop(keys)
return type(keys.rhs) == "string" and (keys.rhs == "" or keys.rhs:lower() == "<nop>")
end
---@param keys LazyKeys
function M:_add(keys)
local lhs = keys.lhs
@ -109,7 +114,7 @@ function M:_add(keys)
---@param buf? number
local function add(buf)
if type(keys.rhs) == "string" and (keys.rhs == "" or keys.rhs:lower() == "<nop>") then
if M.is_nop(keys) then
return self:_set(keys, buf)
end
@ -147,7 +152,7 @@ function M:_add(keys)
vim.api.nvim_create_autocmd("FileType", {
pattern = keys.ft,
callback = function(event)
if self.active[keys.id] then
if self.active[keys.id] and not M.is_nop(keys) then
add(event.buf)
else
-- Only create the mapping if its managed by lazy