diff options
Diffstat (limited to 'lua/telescope/actions/utils.lua')
| -rw-r--r-- | lua/telescope/actions/utils.lua | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lua/telescope/actions/utils.lua b/lua/telescope/actions/utils.lua index f2abfe1..7c8a3ac 100644 --- a/lua/telescope/actions/utils.lua +++ b/lua/telescope/actions/utils.lua @@ -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 |
