From 94b0d24483d56f3777ee0c8dc51675f21709318c Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Tue, 26 Dec 2023 17:39:19 +0000 Subject: [PATCH] fix(nui): prevent double-callback in ui.select (#131) --- lua/dressing/select/nui.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lua/dressing/select/nui.lua b/lua/dressing/select/nui.lua index da3412a..6cae3f9 100644 --- a/lua/dressing/select/nui.lua +++ b/lua/dressing/select/nui.lua @@ -24,6 +24,13 @@ M.select = function(config, items, opts, on_choice) } end + local callback + callback = function(...) + on_choice(...) + -- Prevent double-calls + callback = function() end + end + local border = vim.deepcopy(config.border) border.text = { top = opts.prompt, @@ -48,10 +55,12 @@ M.select = function(config, items, opts, on_choice) submit = { "" }, }, on_close = function() - on_choice(nil, nil) + vim.schedule(function() + callback(nil, nil) + end) end, on_submit = function(item) - on_choice(item.value, item.idx) + callback(item.value, item.idx) end, })