fix: always close keymap help window (#17)
This commit is contained in:
parent
db5a311bc1
commit
7b703b42da
1 changed files with 17 additions and 1 deletions
|
|
@ -85,7 +85,7 @@ M.show_help = function(keymaps)
|
||||||
|
|
||||||
local editor_width = vim.o.columns
|
local editor_width = vim.o.columns
|
||||||
local editor_height = util.get_editor_height()
|
local editor_height = util.get_editor_height()
|
||||||
vim.api.nvim_open_win(bufnr, true, {
|
local winid = vim.api.nvim_open_win(bufnr, true, {
|
||||||
relative = "editor",
|
relative = "editor",
|
||||||
row = math.max(0, (editor_height - #lines) / 2),
|
row = math.max(0, (editor_height - #lines) / 2),
|
||||||
col = math.max(0, (editor_width - max_line - 1) / 2),
|
col = math.max(0, (editor_width - max_line - 1) / 2),
|
||||||
|
|
@ -95,6 +95,22 @@ M.show_help = function(keymaps)
|
||||||
style = "minimal",
|
style = "minimal",
|
||||||
border = "rounded",
|
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
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue