mirror of
https://github.com/zoriya/telescope.nvim.git
synced 2026-08-16 02:45:09 +00:00
fix(actions): which_key after mappings rework (#2556)
(cherry picked from commit 42267407ae)
This commit is contained in:
@@ -81,25 +81,25 @@ 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
|
||||
for _, mapping in ipairs(vim.api.nvim_buf_get_keymap(prompt_bufnr, mode)) do
|
||||
-- ensure only telescope mappings
|
||||
if mapping.rhs and string.find(mapping.rhs, [[require%('telescope.mappings'%).execute_keymap]]) then
|
||||
local funcid = findnth(mapping.rhs, 2)
|
||||
table.insert(ret, { mode = mode, keybind = mapping.lhs, func = __TelescopeKeymapStore[prompt_bufnr][funcid] })
|
||||
if mapping.desc then
|
||||
if mapping.desc:sub(1, 10) == "telescope|" then
|
||||
table.insert(ret, { mode = mode, keybind = mapping.lhs, desc = mapping.desc:sub(11) })
|
||||
elseif mapping.desc:sub(1, 11) == "telescopej|" then
|
||||
local fname = utils._get_anon_function_name(vim.json.decode(mapping.desc:sub(12)))
|
||||
fname = fname:lower() == mapping.lhs:lower() and "<anonymous>" or fname
|
||||
table.insert(ret, {
|
||||
mode = mode,
|
||||
keybind = mapping.lhs,
|
||||
desc = fname,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -107,9 +107,8 @@ function utils.get_registered_mappings(prompt_bufnr)
|
||||
end
|
||||
|
||||
-- Best effort to infer function names for actions.which_key
|
||||
function utils._get_anon_function_name(func_ref)
|
||||
function utils._get_anon_function_name(info)
|
||||
local Path = require "plenary.path"
|
||||
local info = debug.getinfo(func_ref)
|
||||
local fname
|
||||
-- if fn defined in string (ie loadstring) source is string
|
||||
-- if fn defined in file, source is file name prefixed with a `@´
|
||||
|
||||
Reference in New Issue
Block a user