From d00d9df48c00d8682c14c2b5da78bda7ef06b939 Mon Sep 17 00:00:00 2001 From: James Trew <66286082+jamestrew@users.noreply.github.com> Date: Mon, 15 Apr 2024 21:03:24 -0400 Subject: [PATCH] fix(which_key): close window on mouse click action (#3053) * fix(which_key): close window on mouse click action `nvim_buf_delete` is not allowed during text change or window change. Window switching with left mouse click was leading to race condition/error. * [docgen] Update doc/telescope.txt skip-checks: true --------- Co-authored-by: Github Actions --- doc/telescope.txt | 2 ++ lua/telescope/actions/init.lua | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index 690298d..2388431 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -3678,6 +3678,8 @@ action_generate.which_key({opts}) *telescope.actions.generate.which_key()* "TelescopePromptBorder") {winblend} (number) pseudo-transparency of keymap hints floating window + {zindex} (number) z-index of keymap hints floating + window (default: 100) diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua index d0fa0f5..c8bef1d 100644 --- a/lua/telescope/actions/init.lua +++ b/lua/telescope/actions/init.lua @@ -1428,9 +1428,11 @@ actions.which_key = function(prompt_bufnr, opts) 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) + vim.schedule(function() + pcall(vim.api.nvim_win_close, km_win_id, true) + pcall(vim.api.nvim_win_close, km_opts.border.win_id, true) + utils.buf_delete(km_buf) + end) end, }) end)