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

bug: builtin spell suggestion is displayed when cancelled with q or enter #461

Closed xu-cheng closed 1 year ago

xu-cheng commented 1 year ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.9.0

Operating system/version

macOS 13.4

Describe the bug

When using builtin spell suggestion, pressing q or enter will cancel the suggestion, i.e., closing the suggestion view. The which-key plugin should mimic the same behaviour. However, currently after pressing q or enter, which-key will close its own suggestion view then show the builtin spell suggestion. The UX is even worse if noice.nvim is also installed. In the latter case, the user has to switch to the popup window to close it.

Steps To Reproduce

  1. Load repro.
  2. Open a file and write some text.
  3. Attempt to spell suggest a word z=.
  4. Try to quit the suggestion using q or enter.

Expected Behavior

which-key spelling suggestion is closed. The builtin one is not opened.

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  "folke/which-key.nvim",
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

local wk = require("which-key")
wk.setup({
    plugins = {
        spelling = {
            enabled = true,
            suggestions = 20,
        }
    }
})

vim.opt.spell = true 
vim.opt.spelllang = { "en_us" }
folke commented 1 year ago

Just use <esc> instead?

xu-cheng commented 1 year ago

Yes, <esc> works. But it would be better if it can support the same keymap as the builtin one.

folke commented 1 year ago

Unfortunately that's not easy to add

xu-cheng commented 1 year ago

Ok. I guess I will choose to use the builtin spell suggestion in the mean time. May I ask a related question? If I want to use the builtin one, how can I stop noice.nvim to replace its UI?

folke commented 1 year ago

The suggestions come in as a msg_show.echo message, so there's no way to know these are spelling suggestions. Just disable Noice as well

xu-cheng commented 1 year ago

Thanks for the suggestion. I will leave the issue as it is then. Feel free to close it if you don't want to support this feature in the near future.