How to exit visual mode after mounting Menu? #65
-
Which, makes sense because autocmd for the buffer has already fired by the time we get to the second line below. Or at least, that is my assumption. menu:mount()
menu:on(event.BufEnter, function()
vim.notify('hi')
end) When trying to register the event handler before mounting, I am met with a wall of errors. The reason I came about this was actually based on another "bug", which is that if a popup opens while the previous buffer was in visual mode, the popup will also render starting in visual mode. Which is obviously not ideal for a menu picker. What would be the best way to either have this even properly catch for the popup OR for normal mode to be the default mode when mounting popups? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Yes, you're absolutely right.
Same reason as above. Mapping is done on the buffer, but before mounting the buffer does not exist yet.
You can do this before calling if vim.fn.mode() ~= "n" then
vim.api.nvim_input("<Esc>")
end or after calling vim.api.nvim_buf_call(menu.bufnr, function()
if vim.fn.mode() ~= "n" then
vim.api.nvim_input("<Esc>")
end
end) I'm not sure if doing this by default inside What is your usecase by the way? Why are you letting user open a menu while in visual mode? |
Beta Was this translation helpful? Give feedback.
-
vim.api.nvim_buf_call(menu.bufnr, function()
if vim.fn.mode() ~= "n" then
vim.api.nvim_input("<Esc>")
end
end) Ahh, I knew there was a simpler way to do it! This works perfectly thank you. 🙏 For reference, I am working on a new plugin Cosmic-ui that will utilize nui for setting up floating windows for some LSP utilities. Specifically with this issue, I was working on ranged code actions which is why the previous buffer would be in visual mode. |
Beta Was this translation helpful? Give feedback.
Yes, you're absolutely right.
Same reason as above. Mapping is done on the buffer, but before mounting the buffer does not exist yet.