feat (keymaps): add configuration options (#1703)
This commit is contained in:
@@ -952,18 +952,28 @@ end
|
||||
|
||||
-- TODO: make filtering include the mapping and the action
|
||||
internal.keymaps = function(opts)
|
||||
local modes = { "n", "i", "c" }
|
||||
local keymaps_table = {}
|
||||
opts.modes = vim.F.if_nil(opts.modes, { "n", "i", "c", "x" })
|
||||
opts.show_plug = vim.F.if_nil(opts.show_plug, true)
|
||||
|
||||
local keymap_encountered = {} -- used to make sure no duplicates are inserted into keymaps_table
|
||||
local keymaps_table = {}
|
||||
local max_len_lhs = 0
|
||||
for _, mode in pairs(modes) do
|
||||
local function extract_keymaps(keymaps)
|
||||
for _, keymap in pairs(keymaps) do
|
||||
table.insert(keymaps_table, keymap)
|
||||
max_len_lhs = math.max(max_len_lhs, string.len(keymap.lhs or ""))
|
||||
|
||||
-- helper function to populate keymaps_table and determine max_len_lhs
|
||||
local function extract_keymaps(keymaps)
|
||||
for _, keymap in pairs(keymaps) do
|
||||
local keymap_key = keymap.buffer .. keymap.mode .. keymap.lhs -- should be distinct for every keymap
|
||||
if not keymap_encountered[keymap_key] then
|
||||
keymap_encountered[keymap_key] = true
|
||||
if opts.show_plug or not string.find(keymap.lhs, "<Plug>") then
|
||||
table.insert(keymaps_table, keymap)
|
||||
max_len_lhs = math.max(max_len_lhs, #utils.display_termcodes(keymap.lhs))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for _, mode in pairs(opts.modes) do
|
||||
local global = vim.api.nvim_get_keymap(mode)
|
||||
local buf_local = vim.api.nvim_buf_get_keymap(0, mode)
|
||||
extract_keymaps(global)
|
||||
|
||||
Reference in New Issue
Block a user