snacks.nvim icon indicating copy to clipboard operation
snacks.nvim copied to clipboard

bug: Snacks.explorer `<esc>` doesn't work when trying to `explorer_add` file

Open dpetka2001 opened this issue 7 months ago • 1 comments

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

  1. Use the aforementioned repro.lua with nvim --clean -u repro.lua
  2. Open explorer with :lua Snacks.explorer() and press a to add a file. Subsequently press <esc> to exit insert mode. Cursor is stuck
  3. Comment out the noice.nvim plugin spec and restart Neovim (so that noice.nvim can be installed) following steps 1 and 2. Cursor shows correctly in normal mode 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
  },
})

dpetka2001 avatar May 02 '25 17:05 dpetka2001

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>"} } } } }
      },
    },
  },
})

timilio avatar May 29 '25 11:05 timilio

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.

github-actions[bot] avatar Jul 30 '25 02:07 github-actions[bot]

no

dpetka2001 avatar Jul 30 '25 07:07 dpetka2001

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.

github-actions[bot] avatar Sep 01 '25 02:09 github-actions[bot]

.

dpetka2001 avatar Sep 01 '25 04:09 dpetka2001

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.

github-actions[bot] avatar Oct 03 '25 02:10 github-actions[bot]

.

dpetka2001 avatar Oct 03 '25 06:10 dpetka2001

This seems to be solved since I can no longer reproduce this.

folke avatar Oct 21 '25 11:10 folke

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.

dpetka2001 avatar Oct 21 '25 11:10 dpetka2001

added that vim.schedule.

Weird that it worked when noice was eabled

folke avatar Oct 21 '25 11:10 folke

Yep, can confirm all is good with latest commit 😄

dpetka2001 avatar Oct 21 '25 11:10 dpetka2001