Skip to content

Commit

Permalink
fix(nui): prevent double-callback in ui.select (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Dec 26, 2023
1 parent 8b7ae53 commit 94b0d24
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lua/dressing/select/nui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -48,10 +55,12 @@ M.select = function(config, items, opts, on_choice)
submit = { "<CR>" },
},
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,
})

Expand Down

0 comments on commit 94b0d24

Please sign in to comment.