Skip to content

Commit

Permalink
fix(fzf-lua): canceling selection breaks future invocations of vim.ui…
Browse files Browse the repository at this point in the history
….select
  • Loading branch information
stevearc committed Jan 25, 2024
1 parent 42d767b commit 9f9b773
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lua/dressing/select/fzf_lua.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,27 @@ M.select = function(config, items, opts, on_choice)
end
-- Defer the callback to allow the mode to fully switch back to normal after the fzf terminal
local deferred_on_choice = function(...)
local cb = on_choice
on_choice = function() end
local args = vim.F.pack_len(...)
vim.defer_fn(function()
on_choice(vim.F.unpack_len(args))
cb(vim.F.unpack_len(args))
end, 10)
end
return ui_select.ui_select(items, opts, deferred_on_choice)
ui_select.ui_select(items, opts, deferred_on_choice)

-- Because fzf-lua doesn't call the on_choice function if exited (e.g. with <C-c>), we need to
-- add an autocmd ourselves to make sure that happens.
vim.api.nvim_create_autocmd("BufUnload", {
buffer = vim.api.nvim_get_current_buf(),
once = true,
nested = true,
callback = function()
local cb = on_choice
on_choice = function() end
cb()
end,
})
end

return M

0 comments on commit 9f9b773

Please sign in to comment.