fix(which_key): always close on telescope prompt exit
* Add autocmd to make `which_key` window close on prompt exit Currently `actions.which_key` supports a `close_with_action` option (default true). When this is set, the `which_key` window will close after any Telescope action is triggered. This makes sense. However, when it is false, the `which_key` window remains open even after Telescope closes. This seems like a bug. This PR fixes this by setting an autocommand when `close_with_action` is false to close on prompt exit. * [docgen] Update doc/telescope.txt skip-checks: true * Add autocmd to make `which_key` window close on prompt exit Currently `actions.which_key` supports a `close_with_action` option (default true). When this is set, the `which_key` window will close after any Telescope action is triggered. This makes sense. However, when it is false, the `which_key` window remains open even after Telescope closes. This seems like a bug. This PR fixes this by setting an autocommand when `close_with_action` is false to close on prompt exit. --------- Co-authored-by: Github Actions <actions@github>
This commit is contained in:
@@ -1407,20 +1407,27 @@ actions.which_key = function(prompt_bufnr, opts)
|
||||
end
|
||||
end
|
||||
|
||||
-- only set up autocommand after showing preview completed
|
||||
-- if close_with_action is true, close the which_key window when any action is triggered
|
||||
-- otherwise close the window when the prompt buffer is closed
|
||||
local close_event, close_pattern, close_buffer
|
||||
if opts.close_with_action then
|
||||
vim.schedule(function()
|
||||
vim.api.nvim_create_autocmd("User", {
|
||||
pattern = "TelescopeKeymap",
|
||||
once = true,
|
||||
callback = function()
|
||||
pcall(vim.api.nvim_win_close, km_win_id, true)
|
||||
pcall(vim.api.nvim_win_close, km_opts.border.win_id, true)
|
||||
require("telescope.utils").buf_delete(km_buf)
|
||||
end,
|
||||
})
|
||||
end)
|
||||
close_event, close_pattern, close_buffer = "User", "TelescopeKeymap", nil
|
||||
else
|
||||
close_event, close_pattern, close_buffer = "BufWinLeave", nil, prompt_bufnr
|
||||
end
|
||||
-- only set up autocommand after showing preview completed
|
||||
vim.schedule(function()
|
||||
vim.api.nvim_create_autocmd(close_event, {
|
||||
pattern = close_pattern,
|
||||
buffer = close_buffer,
|
||||
once = true,
|
||||
callback = function()
|
||||
pcall(vim.api.nvim_win_close, km_win_id, true)
|
||||
pcall(vim.api.nvim_win_close, km_opts.border.win_id, true)
|
||||
require("telescope.utils").buf_delete(km_buf)
|
||||
end,
|
||||
})
|
||||
end)
|
||||
end
|
||||
|
||||
--- Move from a none fuzzy search to a fuzzy one<br>
|
||||
|
||||
Reference in New Issue
Block a user