Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoclose popup window on leave #42

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ignore = {
"631", -- max_line_length
}
read_globals = {
globals = {
"vim",
}
19 changes: 13 additions & 6 deletions lua/fzy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ end
function M.new_popup()
local buf = api.nvim_create_buf(false, true)
api.nvim_buf_set_keymap(buf, 't', '<ESC>', '<C-\\><C-c>', {})
api.nvim_buf_set_option(buf, 'bufhidden', 'wipe')
local columns = api.nvim_get_option('columns')
local lines = api.nvim_get_option('lines')
vim.bo[buf].bufhidden = "wipe"
local columns = vim.o.columns
local lines = vim.o.lines
local width = math.floor(columns * 0.9)
local height = math.floor(lines * 0.8)
local opts = {
Expand Down Expand Up @@ -156,9 +156,16 @@ function M.execute(choices_cmd, on_choice, prompt)
vim.cmd('stopinsert')
end
local tmpfile = vfn.tempname()
local shell = api.nvim_get_option('shell')
local shellcmdflag = api.nvim_get_option('shellcmdflag')
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 })
Expand All @@ -168,7 +175,7 @@ function M.execute(choices_cmd, on_choice, prompt)
command = 'startinsert!',
once = true,
})
local args = {shell, shellcmdflag, fzy}
local args = {vim.o.shell, vim.o.shellcmdflag, fzy}
vfn.termopen(args, {
on_exit = function()
-- popup could already be gone if user closes it manually; Ignore that case
Expand Down
Loading