Replies: 11 comments
-
Sometimes going through the trouble of explaining a problem helps to figure it out on your own. Setting |
Beta Was this translation helpful? Give feedback.
-
local function test_98()
-- example from https://github.com/MunifTanjim/nui.nvim/tree/main/lua/nui/popup
local popup = Popup({
position = "50%",
size = {
width = 80,
height = 40,
},
enter = true,
focusable = true,
zindex = 50,
relative = "editor",
border = {
padding = {
top = 2,
bottom = 2,
left = 3,
right = 3,
},
style = "rounded",
text = {
top = " I am top title ",
top_align = "center",
bottom = "I am bottom title",
bottom_align = "left",
},
},
buf_options = {
modifiable = true,
readonly = false,
},
win_options = {
winblend = 10,
winhighlight = "Normal:Normal,FloatBorder:FloatBorder",
},
})
popup:mount()
popup:on({ event.BufLeave, event.BufDelete }, function()
popup:unmount()
end, { once = true })
end I can't reproduce the issue with the code above 🤔 Doing both |
Beta Was this translation helpful? Give feedback.
-
Which neovim version are you using? I'm on latest head: |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick reply! Strange, I swear my example was not working before but it is working now. 🤷 One thing that is still an issue is that it is the BufLeave event that is actually closing the window in this example, not BufDelete. If you want to allow the window to be unfocused, say because you want a popup over your popup, then you can't use BufLeave and there needs to be another solution to prevent creating an orphaned border window. |
Beta Was this translation helpful? Give feedback.
-
Can you try popup:on({ event.BufWinLeave }, function()
vim.schedule(function()
popup:unmount()
end)
end, { once = true }) |
Beta Was this translation helpful? Give feedback.
-
The can be many variants of this scenario... it depends on what you're trying to do and what buffer options you've set. Just need to choose the right solution for the situation at hand 😄 I hope this helps. |
Beta Was this translation helpful? Give feedback.
-
BufWinLeave almost works, but I get this error:
BufHidden does the same thing. However, using schedule_wrap seems to fix that issue: popup:on({ event.BufHidden }, function()
vim.schedule_wrap(function ()
popup:unmount()
end)()
end, { once = true }) I don't know if I am just abusing that function like a javascript developer uses setTimeout() though! If this is a correct solution, maybe there should be a simple way to declare this behavior, or add it to the documentation? |
Beta Was this translation helpful? Give feedback.
-
You shouldn't need to use vim.schedule(function()
popup:unmount()
end) I think in this case, this is the right solution. Using |
Beta Was this translation helpful? Give feedback.
-
Your're right. I'm moving so quickly I didn't even notice you added the vim.schedule() to your code and I was just changing the event names when I tested. Sorry for the confusion, your suggested code works perfectly. |
Beta Was this translation helpful? Give feedback.
-
Like I said, there can be other variations of this situation. So we can't do this by default inside Well, once you know which autocmd event to use, it's pretty simple already.
You can add this to Wiki if you want: https://github.com/MunifTanjim/nui.nvim/wiki/nui.popup I think it would be helpful for others 😃 Closing this issue since it's solved. |
Beta Was this translation helpful? Give feedback.
-
Turns out vim has a |
Beta Was this translation helpful? Give feedback.
-
I've noticed a bug with the popup window that happens consistently. If the window is closed in any way other than calling the unmount() method, the inner window is destroyed but the outer border window remains and it is (nearly) impossible for the end user to close it.
Examples of what cause this would be executing
:q
orCTRL+w q
in the popup window.I tried it with the example at https://github.com/MunifTanjim/nui.nvim/tree/main/lua/nui/popup and had the same result.
I would think that setting this event handler would handle the window close situation, but it does not:
Any ideas on how to force unmount to happen when the inner window closes?
Beta Was this translation helpful? Give feedback.
All reactions