Skip to content

How to close popup when cursor on parent buffer moves? #80

Answered by MunifTanjim
anuvyklack asked this question in Q&A
Discussion options

You must be logged in to vote

Do you want the popup to close when

  • the cursor inside popup is moved?
  • the cursor on the buffer outside the popup is moved?
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()

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by anuvyklack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants
Converted from issue

This discussion was converted from issue #79 on December 29, 2021 06:28.