fix: always close keymap help window

This commit is contained in:
Steven Arcangeli 2023-01-05 10:10:39 -08:00
parent 1dda335878
commit 17f97fd2ca

View file

@ -85,7 +85,7 @@ M.show_help = function(keymaps)
local editor_width = vim.o.columns
local editor_height = vim.o.lines - vim.o.cmdheight
vim.api.nvim_open_win(bufnr, true, {
local winid = vim.api.nvim_open_win(bufnr, true, {
relative = "editor",
row = math.max(0, (editor_height - #lines) / 2),
col = math.max(0, (editor_width - max_line - 1) / 2),
@ -95,6 +95,22 @@ M.show_help = function(keymaps)
style = "minimal",
border = "rounded",
})
local function close()
if vim.api.nvim_win_is_valid(winid) then
vim.api.nvim_win_close(winid, true)
end
end
vim.api.nvim_create_autocmd("BufLeave", {
callback = close,
once = true,
nested = true,
buffer = bufnr,
})
vim.api.nvim_create_autocmd("WinLeave", {
callback = close,
once = true,
nested = true,
})
end
return M