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: Leader key unresponsive after closing telescope dialog #783

Closed Kuwagata closed 1 month ago

Kuwagata commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.10.0

Operating system/version

MacOS 11.5

Describe the bug

Which-key works with my leader key (space) until I open telescope's built-in find files using the binding <leader>ff. If I don't select a file, and instead exit the dialog, my leader key (space) no longer triggers which-key. Similar to #781, telescope locally maps space to select results. This wasn't happening until the v3 update, or possibly a minor version change thereafter.

I narrowed it down in my telescope configuration to when I set the normal keymaps in its options:

opts = {
  defaults = {
    mappings = {
      n = {
        ["<space>"] = {
          "toggle_selection",
          type = "action_key",
          opts = { nowait = true, silent = true },
        },
      },
    },
  },
}

Steps To Reproduce

  1. Press space ff to toggle telescope's find files
  2. Press escape to quit the telescope dialog without selecting a file
  3. Press space and which-key is no longer triggered

Expected Behavior

Which-key should be triggered after telescope exits its dialog, as it has in the past.

Health

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

- OK Most of these checks are for informational purposes only.
  WARNINGS should be treated as a warning, and don't necessarily indicate a problem with your config.
  Please |DON't| report these warnings as an issue.

Checking your config ~
- OK |mini.icons| is installed
- OK |nvim-web-devicons| is installed

Checking for issues with your mappings ~
- OK No issues reported

checking for overlapping keymaps ~
- WARNING In mode `n`, <ys> overlaps with <yss>:
  - <ys>: Add a surrounding pair around a motion (normal mode)
  - <yss>: Add a surrounding pair around the current line (normal mode)
- WARNING In mode `n`, <yS> overlaps with <ySS>:
  - <yS>: Add a surrounding pair around a motion, on new lines (normal mode)
  - <ySS>: Add a surrounding pair around the current line, on new lines (normal mode)
- WARNING In mode `n`, <gm> overlaps with <gmm>:
  - <gm>: Multiply operator
  - <gmm>: Multiply line
- WARNING In mode `n`, <gs> overlaps with <gss>:
  - <gs>: Sort operator
  - <gss>: Sort line
- WARNING In mode `n`, <g=> overlaps with <g==>:
  - <g=>: Evaluate operator
  - <g==>: Evaluate line
- WARNING In mode `n`, <gc> overlaps with <gcc>:
  - <gc>: Toggle comment
  - <gcc>: Toggle comment line
- WARNING In mode `n`, <gx> overlaps with <gxx>:
  - <gx>: Exchange operator
  - <gxx>: Exchange line
- WARNING In mode `n`, <gr> overlaps with <grr>:
  - <gr>: Replace operator
  - <grr>: Replace line
- OK Overlapping keymaps are only reported for informational purposes.
  This doesn't necessarily mean there is a problem with your config.

Checking for duplicate mappings ~
- OK No duplicate mappings found

### Log

```log
Debug Started for v3.12.0
new Mode(n:1)
Trigger(add) Mode(n:1) ` ' " g` g' z= <C-W> [ g z ] <Space>
on_key: <Space>
State(start): Mode(n:0) Node(<Space>) { keys = "<Space>" }
  update Mode(n:1)
  continue: <Space> Mode(n:1)
  getchar
  on_key: f
  got: f
  continue: <Space>f Mode(n:1)
  getchar
  on_key: f
  got: f
  suspend: Mode(n:1)
  Trigger(del) Mode(n:1) " g` g' z= <C-W> [ g z ` <Space> ] '
  feedkeys: Mode(n:1) <Space>ff
on_key: <Space>ff
BufNew(6)
BufNew(7)
BufNew(8)
BufNew(9)
BufNew(10)
BufNew(11)
BufEnter(10)
  new Mode(n:10)
ModeChanged(n:i)
  new Mode(i:10)
  Safe(true)
Trigger(add) Mode(n:1) ` ' " g` g' z= <C-W> [ g z ] <Space>
Trigger(add) Mode(n:10) ` ' " g` g' z= <C-W> [ g z ] <Space>
Trigger(add) Mode(i:10) <C-R>
on_key: <Esc>
ModeChanged(i:n)
  Safe(true)
on_key: <Esc>
BufEnter(1)
on_key: <Space>
on_key: <Esc>
on_key: :
ModeChanged(n:c)
  new Mode(c:1)
  Safe(true)
Trigger(add) Mode(c:1) <C-R>
on_key: q
on_key: <CR>
ModeChanged(c:n)
  Unsafe(command-mode)
  suspend: Mode(n:1)
  Trigger(del) Mode(n:1) ` ' " g` g' z= <C-W> [ g z ]
Trigger(add) Mode(n:1) ` ' " g` g' z= <C-W> [ g z ] <Space>

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

vim.g.mapleader = " "

require("lazy.minit").repro({
  spec = {
    {
      "folke/which-key.nvim",
      event = "VeryLazy",
      dependencies = {
        "echasnovski/mini.icons",
      },
      opts = {},
    },
    {
      "nvim-telescope/telescope.nvim",
      lazy = true,
      branch = "0.1.x",
      dependencies = {
        "nvim-lua/plenary.nvim",
      },
      opts = {
        defaults = {
          mappings = {
            n = {
              ["<space>"] = {
                "toggle_selection",
                type = "action_key",
                opts = { nowait = true, silent = true },
              },
            },
          },
        },
      },
      keys = {
        {
          "<leader>ff",
          function()
            return require("telescope.builtin").find_files()
          end,
          desc = "Files",
        },
      },
    },
  },
})
folke commented 1 month ago

Can you please oh please pick a relevant title?

Kuwagata commented 1 month ago

If it helps, manually starting which-key by command re-enables my leader key.

folke commented 1 month ago

Fixed!

Kuwagata commented 1 month ago

Thank you!