feat: show keymaps for builtin actions (#1084)

* Add default mappings `<C-/>`and `?` for insert and normal mode, respectively, to show registered keymappings (`actions.which_key`) attached to prompt buffer
This commit is contained in:
fdschmidt93
2021-09-01 20:11:53 +02:00
committed by GitHub
parent 5d37c3ea08
commit fbe004142f
7 changed files with 385 additions and 1 deletions

View File

@@ -78,4 +78,26 @@ function utils.map_selections(prompt_bufnr, f)
end
end
local findnth = function(str, nth)
local array = {}
for i in string.gmatch(str, "%d+") do
table.insert(array, tonumber(i))
end
return array[nth]
end
--- Utility to collect mappings of prompt buffer in array of `{mode, keybind, name}`.
---@param prompt_bufnr number: The prompt bufnr
function utils.get_registered_mappings(prompt_bufnr)
local ret = {}
for _, mode in ipairs { "n", "i" } do
local mode_mappings = vim.api.nvim_buf_get_keymap(prompt_bufnr, mode)
for _, mapping in ipairs(mode_mappings) do
local funcid = findnth(mapping.rhs, 2)
table.insert(ret, { mode = mode, keybind = mapping.lhs, func = __TelescopeKeymapStore[prompt_bufnr][funcid] })
end
end
return ret
end
return utils