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: Mappings using Ctrl require the <c to be lowercase, but only in the keys spec #771

Closed jcoffa closed 1 month ago

jcoffa commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.10.0

Operating system/version

EndeavourOS Linux - Kernel 6.9.9-arch1-1

Describe the bug

When defining mappings in which-key that use the Ctrl key modifier under the opts.keys spec, which-key requires the <c to be lowercase. This is not typical for expected vim/nvim/which-key behaviour as it normally allows the <c (and the following key as well) to be lowercase or uppercase.

I have verified that mappings work as expected when defining mappings in opts.spec regardless of whether <C- or <c- is used. It seems to only be mappings in the opts.keys spec that require <c- to be used. When I change my opts.keys mappings to use <c- instead of <C-, without changing anything else at all, those mappings begin to work as expected.

Steps To Reproduce

  1. Define any mapping in the which-key spec under the keys section that is intended to use the Ctrl key, but use a capital C instead of a lowercase c (e.g., opts = { keys = { scroll_down = '<C-n>', scroll_up = '<C-p>'} }
  2. Attempt to use the mapping (e.g. by attempting to scroll the which-key output using Ctrl + n and Ctrl + p)

Expected Behavior

Mapping works using Ctrl + <other key> and performs the expected task (in this example, scroll the which-key window up and down to view mappings that didn't fit on the page)

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 ~
- WARNING |mini.icons| is not installed
- WARNING |nvim-web-devicons| is not installed
- WARNING Keymap icon support will be limited.

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

checking for overlapping keymaps ~
- WARNING In mode `n`, <gc> overlaps with <gcc>:
  - <gc>: Toggle comment
  - <gcc>: Toggle comment 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

Debug Started for v3.11.0
new Mode(n:1)
Trigger(add) Mode(n:1) ' " ` g' g` z= g z ] [ <C-W>
on_key: <C-E>
on_key: <C-R>
on_key: d
ModeChanged(n:no)
  new Mode(o:1)
  Safe(true)
  State(start): Mode(o:0) Node() { defer = false }
    update Mode(o:1)
    continue:  Mode(o:1)
    getchar
    Trigger(add) Mode(o:1) g [ ]
    on_key: <C-N>
    got: <C-N>
    suspend: Mode(o:1)
    Trigger(del) Mode(o:1) ] [ g
    feedkeys: Mode(o:1) <C-N>
on_key: <C-N>
ModeChanged(no:n)
  Safe(true)
Trigger(add) Mode(o:1) g [ ]
on_key: y
ModeChanged(n:no)
  Safe(true)
  State(start): Mode(o:0) Node() { defer = false }
    update Mode(o:1)
    continue:  Mode(o:1)
    getchar
    on_key: <C-P>
    got: <C-P>
    suspend: Mode(o:1)
    Trigger(del) Mode(o:1) ] [ g
    feedkeys: Mode(o:1) <C-P>
on_key: <C-P>
ModeChanged(no:n)
  Safe(true)
Trigger(add) Mode(o:1) g [ ]
on_key: :
ModeChanged(n:c)
  new Mode(c:1)
  Safe(true)
Trigger(add) Mode(c:1) <C-R>
on_key: q
on_key: !
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= g z ] [ <C-W>

Repro

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 = {
        spec = {
          -- Both of these mappings work as expected
          { '<C-e>', function() print('<C-e> mapping worked!') end },
          { '<c-r>', function() print('<c-r> mapping worked!') end },
        },
        keys = {
          -- These only work if the '<C' part is lowercase
          -- i.e. <c-n> and <c-p>
          scroll_down = '<C-n>',
          scroll_up = '<C-p>',
        },
      },
    },
  },
})