folke / which-key.nvim

💥 Create key bindings that stick. WhichKey helps you remember your Neovim keymaps, by showing available keybindings in a popup as you type.
Apache License 2.0
5.12k stars 163 forks source link

bug: Icons are only applied to groups #637

Closed eslam-allam closed 1 month ago

eslam-allam commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.11.0-dev+402-g028dd3c5c

Operating system/version

linux fedora-40

Describe the bug

Adding icons to a group works just fine, and it's also inherited by other groups nested within it. However, there are some observations I've found that don't seem to be intended:

I'm not sure if these points are intended or not but it seems counter intuitive as keymaps automatically set by the predefined pattern rules seem to apply to keymaps and groups equally.

Steps To Reproduce

  1. Create a which key mapping for anything and explicitly set an icon
  2. Observe how the mapping is shown on the whichkey window

Expected Behavior

keymaps should support icons just like groups do.

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  { "folke/which-key.nvim", opts = {} },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

require("which-key").add({
"gj",
group = "Something",
icon = "",
{ "gjw", "<cmd>echo 'hello'<CR>", desc = "print hello"},
{ "gjr", "<cmd>echo 'hello again'<CR>", desc = "print hello again", icon = ""},
})
eslam-allam commented 1 month ago

Interestingly enough, the icons are inherited properly in this one:

      require("which-key").add({
        "<leader>cj",
        icon = { icon = "", color = "orange" },
        buffer = args.buf,
        group = "jdtls",
        { "<leader>cjw", "<cmd>JdtWipeDataAndRestart<CR>", desc = "Wipe and Restart" },
        { "<leader>cjc", "<cmd>JdtCompile<CR>", desc = "Compile" },
        { "<leader>cjs", "<cmd>JdtSetRuntime<CR>", desc = "Set Runtime" },
        {
          "<leader>cju",
          rhs = function()
            require("jdtls").update_projects_config({ select_mode = "all" })
          end,
          desc = "Update Config",
        },
        { "<leader>cjr", "<cmd>JdtRestart<CR>", desc = "Restart" },
        { "<leader>cjj", "<cmd>JdtJshell<CR>", desc = "JShell" },
      })
    end

I cannot figure out why this one works when the one in the min repro doesnt.