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: Which Key seems to affect keymap #648

Closed iamxiaojianzheng closed 1 month ago

iamxiaojianzheng commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

v0.10.0

Operating system/version

windows11

Describe the bug

When I press a d, the following message appears.

image

When I press dd or <C-x>, the following message appears.

image

Steps To Reproduce

This is my custom keymap, and it cannot be used normally after updating to the latest lazyvim.

local map = LazyVim.safe_keymap_set
map({ "n", "o" }, "dd", '"_dd', { desc = "Delete Line" })
map({ "n", "v" }, "<C-x>", "dd", { desc = "Cut Line" })

Expected Behavior

Normally the current line should be deleted or cut.

Health

============================================================================== which-key: require("which-key.health").check()

Checking for issues with your mappings ~

checking for overlapping keymaps ~

Checking for duplicate mappings ~

  • OK No duplicate mappings found

Log

No response

Repro

No response

Rizhiy commented 1 month ago

Can confirm. I have the following keymaps for telescope:

{ "<leader>f",   function() FuzzyFindFiles() end,  desc = "Fuzzy search" },
{ "<leader>fe",  ":Telescope live_grep<CR>",       desc = "Exact search",                 silent = true },
{ "<leader>fb",  ":Telescope buffers<CR>",         desc = "Search buffers",               silent = true },
...

Notice the overlap. I've defined the following group in which-key:

wk.register({
    f = { name = "Find" },
}, { prefix = "<leader>" })

This used to work fine before v3, now <leader>f doesn't work any more and the submenu is always shown.

Specs:

OS: Ubuntu 22.04
NVIM: NVIM v0.10.0
Whick-key: commit 0427e91

Works fine if I disable which-key as well.

Updating to new syntax doesn't help:

wk.add({
    { "<leader>f", group = "file" },
})
folke commented 1 month ago

@Rizhiy to make that work you need to make sure that opts.delay >= timeoutlen

Rizhiy commented 1 month ago

@folke maybe set opts.delay to timeoutlen by default to maintain previous behaviour?

folke commented 1 month ago

I just pushed a change where which-key now honors nowait and timeoutlen the same as Neovim does, regardless of timeoutlen or delay