bug: Mapping is not hidden when `desc: fun():string` returns `which_key_ignore`
Did you check docs and existing issues?
- [X] I have read all the which-key.nvim docs
- [X] I have updated the plugin to the latest version before submitting this issue
- [X] I have searched the existing issues of which-key.nvim
- [X] I have searched the existing issues of plugins related to this issue
Neovim version (nvim -v)
0.10.2
Operating system/version
Fedora release 41
Describe the bug
The desc parameter in wk.Spec accepts either a string or fun():string. However, the behavior to hide mapping when desc = which_key_ignore only works when desc is of type string.
When desc is of type fun():string, the mapping still shows and the label becomes "which_key_ignore".
I think this is related to #880
Steps To Reproduce
In my .config/nvim/lua/config.autocmds.lua, I have the following code to set up compilation of cpp file
vim.api.nvim_create_autocmd("FileType", {
pattern = "cpp",
callback = function()
vim.keymap.set("n", "<leader>rr", function()
-- some code to compile cpp file ...
end, { buffer = true })
end,
})
In my .config/nvim/lua/plugins/which-key.lua file, I have the following code
local function mapcheck(keymap)
return vim.fn.maparg(keymap, "n") ~= ""
end
local function conditional_desc(keymap, desc)
if mapcheck(keymap) then
return desc
else
return "which_key_ignore"
end
end
return {
"folke/which-key.nvim",
opts = {
spec = {
{
"<leader>rr",
desc = function()
return conditional_desc("<leader>rr", "Run code")
end,
},
}
}
}
Then, open any file that is not a .cpp file. Then click "
Expected Behavior
The mapping should be dynamically hidden / shown based on whether the desc function returns "which_key_ignore" / some other string.
Health
No response
Log
No response
Repro
No response
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.