Skip to content

Commit

Permalink
fix: always close keymap help window
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Jan 5, 2023
1 parent 1dda335 commit 17f97fd
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lua/aerial/keymap_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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

0 comments on commit 17f97fd

Please sign in to comment.