Skip to content

Commit

Permalink
fix: remove defer_fn hack in fzf select (fix #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Dec 23, 2021
1 parent 0bb73bc commit 0ad4d1e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lua/dressing/select/fzf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ end

clear_callback()

M._on_term_close = function()
if vim.v.event.status ~= 0 then
_G.dressing_fzf_cancel()
end
end

M.select = function(config, items, opts, on_choice)
local labels = {}
for i, item in ipairs(items) do
Expand All @@ -29,8 +35,7 @@ M.select = function(config, items, opts, on_choice)
end
vim.fn["dressing#fzf_run"](labels, string.format('--prompt="%s"', opts.prompt), config.window)
-- fzf doesn't have a cancel callback, so we have to make one.
-- the defer_fn is so that we can process the confirm event first
vim.cmd([[autocmd BufLeave <buffer> lua vim.defer_fn(function() dressing_fzf_cancel() end, 5)]])
vim.cmd([[autocmd TermClose <buffer> ++once lua require('dressing.select.fzf')._on_term_close()]])
end

return M

0 comments on commit 0ad4d1e

Please sign in to comment.