From 5ce61c1c9644d620a908b0814dd72706cf3f9dc8 Mon Sep 17 00:00:00 2001 From: Mathias Fussenegger Date: Mon, 27 May 2024 17:34:32 +0200 Subject: [PATCH] Autoclose popup window on leave --- lua/fzy.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lua/fzy.lua b/lua/fzy.lua index 473c30b..2b23bf7 100644 --- a/lua/fzy.lua +++ b/lua/fzy.lua @@ -157,6 +157,15 @@ function M.execute(choices_cmd, on_choice, prompt) end local tmpfile = vfn.tempname() local popup_win, buf = M.new_popup() + api.nvim_create_autocmd("WinLeave", { + callback = function() + local w = vim.api.nvim_get_current_win() + if w == popup_win then + api.nvim_buf_delete(buf, { force = true }) + return true + end + end, + }) local height = api.nvim_win_get_height(popup_win) prompt = prompt and vim.fn.shellescape(prompt) or nil local cmd = M.command({ height = height, prompt = prompt })