fix(Layer): `:unmap`ping

pull/17/head release/3.1.3
Iron-E 2 years ago
parent 21dfc73142
commit 24115079ed
No known key found for this signature in database
GPG Key ID: 19B71B7B7B021D22

@ -1,3 +1,5 @@
local globals = require 'libmodal/src/globals'
--- Normalizes a `buffer = true|false|0` argument into a number.
--- @param buffer boolean|number the argument to normalize
--- @return nil|number
@ -11,6 +13,29 @@ local function normalize_buffer(buffer)
return buffer
end
--- Normalizes a keymap from `vim.api.nvim_get_keymap` so it can be passed to `vim.keymap.set`
--- @param keymap table
--- @return table normalized
local function normalize_keymap(keymap)
-- `buffer == 0` just means "not a buffer mapping"
keymap.buffer = keymap.buffer > 0 and keymap.buffer or nil
-- Keys which are `v:true` or `v:false`
keymap.expr = globals.is_true(keymap.expr)
keymap.noremap = globals.is_true(keymap.noremap)
keymap.nowait = globals.is_true(keymap.nowait)
keymap.silent = globals.is_true(keymap.silent)
-- Keys which should not exist
keymap.lhs = nil
keymap.lnum = nil
keymap.script = nil
keymap.sid = nil
keymap.mode = nil
return keymap
end
--- remove and return the right-hand side of a `keymap`.
--- @param keymap table the keymap to unpack
--- @return function|string rhs, table options
@ -84,8 +109,7 @@ function Layer:map(mode, lhs, rhs, options)
vim.api.nvim_get_keymap(mode)
) do -- check if this keymap will overwrite something
if existing_keymap.lhs == lhs then -- mapping this will overwrite something; log the old mapping
existing_keymap.lhs = nil
self.existing_keymaps_by_mode[mode][lhs] = existing_keymap
self.existing_keymaps_by_mode[mode][lhs] = normalize_keymap(existing_keymap)
break
end
end

Loading…
Cancel
Save