fix(actions): which_key after mappings rework (#2556)

This commit is contained in:
Simon Hauser
2023-06-08 23:10:26 +02:00
committed by GitHub
parent 991d5db624
commit 42267407ae
5 changed files with 36 additions and 37 deletions

View File

@@ -1178,26 +1178,10 @@ actions.which_key = function(prompt_bufnr, opts)
local mappings = {}
local mode = a.nvim_get_mode().mode
for _, v in pairs(action_utils.get_registered_mappings(prompt_bufnr)) do
-- holds true for registered keymaps
if type(v.func) == "table" then
local name = ""
for _, action in ipairs(v.func) do
if type(action) == "string" then
name = name == "" and action or name .. " + " .. action
end
end
if name and name ~= "which_key" and name ~= "nop" then
if not opts.only_show_current_mode or mode == v.mode then
table.insert(mappings, { mode = v.mode, keybind = v.keybind, name = name })
end
end
elseif type(v.func) == "function" then
if v.desc and v.desc ~= "which_key" and v.desc ~= "nop" then
if not opts.only_show_current_mode or mode == v.mode then
local fname = action_utils._get_anon_function_name(v.func)
-- telescope.setup mappings might result in function names that reflect the keys
fname = fname:lower() == v.keybind:lower() and "<anonymous>" or fname
table.insert(mappings, { mode = v.mode, keybind = v.keybind, name = fname })
if fname == "<anonymous>" then
table.insert(mappings, { mode = v.mode, keybind = v.keybind, name = v.desc })
if v.desc == "<anonymous>" then
utils.notify("actions.which_key", {
msg = "No name available for anonymous functions.",
level = "INFO",