bug: Snacks.explorer `<esc>` doesn't work when trying to `explorer_add` file
Did you check docs and existing issues?
- [x] I have read all the snacks.nvim docs
- [x] I have updated the plugin to the latest version before submitting this issue
- [x] I have searched the existing issues of snacks.nvim
- [x] I have searched the existing issues of plugins related to this issue
Neovim version (nvim -v)
NVIM v0.12.0-dev-272+gce8b755a86
Operating system/version
Linux Mint 21.3
Describe the bug
Using the following minimal 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/snacks.nvim",
lazy = false,
opts = {
explorer = {},
},
},
-- {
-- "folke/noice.nvim",
-- opts = {},
-- },
},
})
When opening explorer with :lua Snacks.explorer() and then pressing a to add a file, if you press <esc> from insert mode, the cursor seems to be stuck. You have to press another key to actually see the normal mode.
If you uncomment the noice.nvim plugin spec and repeat the same steps, you will see that it behaves as expected. The difference probably being how :lua Snacks.explorer() is being executed from Neovim's native cmdline and noice.nvim's cmdline.
Wrapping the vim.cmd("stopinsert") in a vim.schedule here https://github.com/folke/snacks.nvim/blob/bc0630e43be5699bb94dadc302c0d21615421d93/lua/snacks/input.lua#L180-L182 seems to solve this problem. Not sure if other parts of the Snacks.input actions need to also be vim.scheduled or even if this is actually the best solution. Credits go to @drowning-cat for finding this out 😄
See also relevant discussion #1837.
Steps To Reproduce
- Use the aforementioned
repro.luawithnvim --clean -u repro.lua - Open explorer with
:lua Snacks.explorer()and pressato add a file. Subsequently press<esc>to exitinsertmode. Cursor is stuck - Comment out the
noice.nvimplugin spec and restart Neovim (so thatnoice.nvimcan be installed) following steps 1 and 2. Cursor shows correctly innormalmode after having pressed<esc>.
Expected Behavior
Cursor should not look like it's stuck in insert mode after pressing <esc> without noice.nvim in the user's configuration.
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/snacks.nvim", opts = {} },
-- add any other plugins here
},
})
I think this is a problem in Snacks.input specifically. A workaround that works for me is to override the "stopinsert" keymap like this.
require("lazy").setup({
spec = {
{
"folke/snacks.nvim",
opts = {
styles = { input = { keys = { i_esc = { [2] = {"cmp_close", "<esc>"} } } } }
},
},
},
})
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
no
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
.
This seems to be solved since I can no longer reproduce this.
Did you actually try the repro.lua file in the OP? If you do nvim -u repro.lua you should be able experience what I'm describing. Open explorer with :lua Snacks.explorer(), then try to add a file by pressing a and when the input appears press <Esc>. The cursor remains in insert mode until you press another key.
I just tested right now.
added that vim.schedule.
Weird that it worked when noice was eabled
Yep, can confirm all is good with latest commit 😄