-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: Keys.update_keymaps only adds, never removes #615
Comments
There is a simple fix for this, simply clearing the buffer local keymaps M.get_tree(mode, buf).tree = Tree:new() Specifically adding this to the file NOTE: however that doing this naive change seems to cause nvim to hang and become unresponsive. The cause seems to be that in addition to the reset of the |
After some more investigation I've found that this also happens with |
I found something that seems to work , will attempt making a PR soon function M.update_keymaps(mode, buf)
---@type Keymap[]
local keymaps = buf and vim.api.nvim_buf_get_keymap(buf, mode) or vim.api.nvim_get_keymap(mode)
-- Clearing up previous tree entries and hooks.
-- Forgetting to do this will break which-key for users that register and de register
-- keymaps in different contexts
do
local function unhook(node)
if node.mapping and M.is_hooked(node.mapping.prefix, mode, buf) then
M.hook_del(node.mapping.prefix, mode, buf)
end
end
M.get_tree(mode, buf).tree:walk(unhook)
M.get_tree(mode, buf).tree = Tree:new()
end |
fixes folke#615 current approach fails to support removal of keymaps this fix ensures that both tree nodes and hooks related to removed keymaps are cleared
I can confirm this issue through trying to resolve LazyVim/LazyVim#3863. Even with the neovim-default keymaps removed through |
I'll see if I can find some time today to fully test that PR. which-key is quite fragile (was my first plugin), so I'm always a bit hesitant to merge a PR. |
Did you check docs and existing issues?
Neovim version (nvim -v)
NVIM v0.10.0 Build type: Release LuaJIT 2.1.1713484068
Operating system/version
Ubuntu 22.04.3 LTS
Describe the bug
When a buffer local keymap is removed, which-key will still show it as if it exists. In other words, which-key only adds buffer local keymaps to the tree, it never removes them.
Steps To Reproduce
Add the following two keymaps, the first one adds the buffer local keymap to current buffer, the second one removes it.
init.lua
.<leader>A
<leader>
and observe howa ->
appears in the which-key help window<leader>S
<leader>
and observe howa ->
still appears in the which-key help windowExpected Behavior
It is expected that in
step 5
of the steps to reproduce, that we no longer see the keymap listed.Repro
The text was updated successfully, but these errors were encountered: