Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not close popup with <Esc> in INSERT mode #1396

Closed
cseickel opened this issue Mar 15, 2024 · 1 comment · Fixed by #1398
Closed

Do not close popup with <Esc> in INSERT mode #1396

cseickel opened this issue Mar 15, 2024 · 1 comment · Fixed by #1398

Comments

@cseickel
Copy link
Contributor

cseickel commented Mar 15, 2024

Also with this new suggested event:

{
  event = "neo_tree_popup_input_ready",
  ---@param input NuiInput
  handler = function(input)
    vim.cmd("stopinsert") -- Enter normal mode
  end,
}

I am unable to enter normal mode after manually entering insert mode with i, since pressing esc even in insert mode just closes the input. Is there a way to make it so that I need to press esc from within normal mode only to exit the input box, as I believe it used to be before?

Originally posted by @uthmanmoh in #1371 (comment)

@pysan3
Copy link
Collaborator

pysan3 commented Mar 16, 2024

@uthmanmoh I've updated the help page and it should be more helpful for you this time.

And of course you can combine the two into one handler (tbh I recommend registering only one handler for this event).

    {
      event = "neo_tree_popup_input_ready",
      handler = function()
        -- enter input popup with normal mode by default.
        vim.cmd("stopinsert")
      end,
    },
    {
      event = "neo_tree_popup_input_ready",
      ---@param args { bufnr: integer, winid: integer }
      handler = function(args)
        -- map <esc> to enter normal mode (by default closes prompt)
        -- don't forget `opts.buffer` to specify the buffer of the popup.
        vim.keymap.set("i", "<esc>", vim.cmd.stopinsert, { noremap = true, buffer = args.bufnr }) 
      end,
    }

BTW if you have something like nnoremap jk <esc> globally, you don't need to remap <esc> for the popup but use jk to get out of insert mode OOTB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants