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

fix(view): which-key popup doesn't close in command line window #503

Closed Subjective closed 5 months ago

Subjective commented 1 year ago

Resolves the following error when attempting to close the which-key popup in the command line window:

E5108: Error executing lua ...al/share/nvim/lazy/which-key.nvim/lua/which-key/view.lua:155: E11: Invalid in command-line window; <CR> executes, CTRL-C quits
stack traceback:
    [C]: in function 'nvim_buf_delete'
    ...al/share/nvim/lazy/which-key.nvim/lua/which-key/view.lua:155: in function 'hide'
    ...al/share/nvim/lazy/which-key.nvim/lua/which-key/view.lua:319: in function 'on_keys'
    ...al/share/nvim/lazy/which-key.nvim/lua/which-key/view.lua:254: in function 'open'
    ...al/share/nvim/lazy/which-key.nvim/lua/which-key/init.lua:49: in function 'show'
    [string ":lua"]:1: in main chunk

See https://github.com/neovim/neovim/issues/24452

konosubakonoakua commented 8 months ago

The command-line window is not a normal window. It is not possible to move to another window or edit another buffer. All commands that would do this are disabled in the command-line window. Of course it is possible to execute any command that you entered in the command-line window. Other text edits are discarded when closing the window.

should we just disable which-key for the cmdline-window?

  {
    "folke/which-key.nvim",
    event = "VeryLazy",
    opts = {
      -- disable the WhichKey popup for certain buf types and file types.
      -- Disabled by default for Telescope
      disable = {
        buftypes = {},
        filetypes = {},
      },
    },
  },

maybe we can add something like disable = {cmdtype={":"}}, according to the following description.

getcmdtype()                                                      *getcmdtype()*
        Return the current command-line type. Possible return values
        are:
            :   normal Ex command
            >   debug mode command |debug-mode|
            /   forward search command
            ?   backward search command
            @   |input()| command
            `-` |:insert| or |:append| command
            =   |i_CTRL-R_=|
        Only works when editing the command line, thus requires use of
        |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
        Returns an empty string otherwise.
        Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
folke commented 5 months ago

Fixed by https://github.com/folke/which-key.nvim/pull/581