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

fix(state): recursion in hydra mode when mapping does not exist #884

Open ANGkeith opened 1 week ago

ANGkeith commented 1 week ago

Description

# minimal.lua
vim.g.mapleader = " "

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

require("lazy.minit").repro({
  spec = {
    { "folke/which-key.nvim", opts = {} },
    -- add any other plugins here
  },
})

local wk = require("which-key")

wk.add({
  {
    "<leader>mq",
    function()
      print("i am mq")
    end,
  },
  {
    "<leader>mw",
    function()
      print("i am mw")
    end,
  },
  {
    "<leader>mj",
    "j",
  },
  {
    "<leader>m",
    function()
      vim.notify("hail hydra")
      require("which-key").show({
        keys = "<leader>m",
        loop = true, -- this will keep the popup open until you hit <esc>
      })
    end,
  },
})

Before this pr, given the above config,

there's currently two problem:

  1. issuing the key <leader>mjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...., we will falsly get the recusion warning
  2. issuing the key <leader>mh, we end up in a recursion

Related Issue(s)