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.38k stars 177 forks source link

bug: Custom registered mappings don't have the correct name #482

Closed MariaSolOs closed 3 months ago

MariaSolOs commented 1 year ago

Did you check docs and existing issues?

Neovim version (nvim -v)

v0.10.0-dev-673+g622ae2f53

Operating system/version

Mac Ventura 13.4.1

Describe the bug

Starting from version >= 1.5.0, mappings that I register using a custom name are displayed using +prefix instead of the name I configured.

Steps To Reproduce

Register a group of commands that have a common prefix and register a name for which-key to use.

For example, I register this set of rust commands when loading rust-tools:

image

But which-key shows +prefix instead of +rust when pressing <leader>R:

image

Interestingly enough, the prefix does appear once I press R:

image

Expected Behavior

For which-key to always show the name I configured.

MariaSolOs commented 1 year ago

Okay I debugged this a bit and removing this line fixes it. For some reason in this call the group has a name but children is empty, while here there are children but the name is gone. An easy fix would be to modify the if condition accordingly, but I'm not sure if the described behaviour is the expected design or another bug :/

abeldekat commented 1 year ago

This occurs starting with commit 8503c0d: fix(keys): don't show empty groups

The commit came shortly after discussing this issue with @folke : empty group names

I see the same problem in LazyVim in the git submenu. This contains the "h" for the "hunks" submenu, labeled "prefix". I expected to solve this using the following code in lua.lazyvim.plugins.editor:

--- fragment of gitsigns setup:
config = function(_, opts)      
     require("gitsigns").setup(opts)
     require("lazyvim.util").on_load("which-key.nvim", function()
         require("which-key").register({ mode = { "n", "v" }, ["<leader>gh"] = { name = "+hunks" } })
       end)
end

No luck, unfortunately. The "h" is still labeled prefix, all inner menu items are present.

My knowledge of the which-key code is very limited. Given this limitation, my suggestion would be:

Do show empty group names, as the user configures a group name with intent. The group name unexpectedly being empty shows a mismatch between the intent of the user and the actual code...

ckt114 commented 10 months ago

This bug seems to be in v1.5.0+ only. Tested with v1.4.0 and it’s working as expected.

Keep-Simple commented 10 months ago

+1

HIDE-r commented 7 months ago

+1

github-actions[bot] commented 4 months ago

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.