which-key.nvim icon indicating copy to clipboard operation
which-key.nvim copied to clipboard

bug: Mapping is not hidden when `desc: fun():string` returns `which_key_ignore`

Open maomao9-0 opened this issue 2 years ago • 2 comments

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 "" followed by "r". Instead of hiding the mapping, it shows "which_key_ignore" instead.

image

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

maomao9-0 avatar Nov 15 '24 08:11 maomao9-0

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.

github-actions[bot] avatar Dec 17 '24 02:12 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Dec 25 '24 01:12 github-actions[bot]