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

QuitPre event not working if set after popup is mounted #236

Closed
xeluxee opened this issue Jan 31, 2023 · 2 comments · Fixed by #237
Closed

QuitPre event not working if set after popup is mounted #236

xeluxee opened this issue Jan 31, 2023 · 2 comments · Fixed by #237

Comments

@xeluxee
Copy link

xeluxee commented Jan 31, 2023

Consider the following working code:

local nui_popup = require("nui.popup")
local nui_event = require("nui.utils.autocmd").event

local popup = nui_popup({
	enter = true,
	border = {
		style = "rounded",
	},
	position = "50%",
	size = "50%",
})

popup:on(nui_event.QuitPre, function()
	print("QuitPre autocommand")
end)

popup:mount()
vim.api.nvim_buf_set_lines(popup.bufnr, 0, 1, false, { "Hello World" })

When I close the popup with :q the callback is executed and "QuitPre autocommand" is printed


But when the autocommand is created after popup is mounted the callback doesn't work:

local nui_popup = require("nui.popup")
local nui_event = require("nui.utils.autocmd").event

local popup = nui_popup({
	enter = true,
	border = {
		style = "rounded",
	},
	position = "50%",
	size = "50%",
})

popup:mount()

popup:on(nui_event.QuitPre, function()
	print("QuitPre autocommand")
end)

vim.api.nvim_buf_set_lines(popup.bufnr, 0, 1, false, { "Hello World" })

When I close the popup with :q nothing happens

@MunifTanjim
Copy link
Owner

@xeluxee can you check if #237 solves the issue for you?

Also if you want to organize multiple popups in a specific layout, you can try nui.layout for that. It already supports the desired behavior for :quit command. If one of the popup in a layout is quitted, the whole layout is unmounted.

@xeluxee
Copy link
Author

xeluxee commented Feb 1, 2023

can you check if #237 solves the issue for you?

Thanks, it solves my issue.

Also if you want to organize multiple popups in a specific layout, you can try nui.layout for that. It already supports the desired behavior for :quit command. If one of the popup in a layout is quitted, the whole layout is unmounted.

I wrote my code before nui.layout existed. Soon or later I'll rewrite it using layouts.

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