How to close popup when cursor on parent buffer moves? #80
Answered
by
MunifTanjim
anuvyklack
asked this question in
Q&A
-
I am trying to create a popup window that will be closed on cursor move, but this code doesn't work: local popup = Popup({
enter = false,
focusable = false,
position = "50%",
size = {
width = "80%",
height = "60%",
},
buf_options = {
modifiable = false,
readonly = true,
},
})
popup:mount()
popup:on(event.CursorMoved, function()
popup:unmount()
end) |
Beta Was this translation helpful? Give feedback.
Answered by
MunifTanjim
Dec 29, 2021
Replies: 1 comment
-
Do you want the popup to close when
popup:on(event.CursorMoved, function()
popup:unmount()
end) What this does is, when the cursor inside the popup is moved, it unmounts the popup. But what you want is something like this: local autocmd = require("nui.utils.autocmd")
local event = require("nui.utils.autocmd").event
-- this is the `bufnr` where it cursor is currently at (where you're editing your file)
local bufnr = vim.api.nvim_get_current_buf()
autocmd.buf.define(bufnr, event.CursorMoved, function()
popup:unmount()
end, { once = true })
popup:mount() |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
anuvyklack
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you want the popup to close when
What this does is, when the cursor inside the popup is moved, it unmounts the popup.
But what you want is something like this: