From 5474df3a722b0efbeb9f47d0b2fdbce7d2ff258e Mon Sep 17 00:00:00 2001 From: bhagwan Date: Sat, 27 Jan 2024 07:20:28 -0500 Subject: [PATCH] fix(ui_select): abort doesn't call `on_choice` (#1014) --- lua/fzf-lua/providers/ui_select.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lua/fzf-lua/providers/ui_select.lua b/lua/fzf-lua/providers/ui_select.lua index a67bdbd1..2669c5b6 100644 --- a/lua/fzf-lua/providers/ui_select.lua +++ b/lua/fzf-lua/providers/ui_select.lua @@ -49,6 +49,7 @@ end M.accept_item = function(selected, o) local idx = selected and tonumber(selected[1]:match("^(%d+)%.")) or nil o._on_choice(idx and o._items[idx] or nil, idx) + o._on_choice_called = true end M.ui_select = function(items, ui_opts, on_choice) @@ -116,9 +117,21 @@ M.ui_select = function(items, ui_opts, on_choice) config.set_action_helpstr(opts.actions["default"], nil) if not selected then + -- with `actions.dummy_abort` this doesn't get called anymore + -- as the action is configured as a valid fzf "accept" (thus + -- `selected` isn't empty), see below comment for mor info on_choice(nil, nil) else + o._on_choice_called = nil actions.act(o.actions, selected, o) + if not o._on_choice_called then + -- see comment above, `on_choice` wasn't called, either + -- "dummy_abort" (ctrl-c/esc) or (unlikely) the user setup + -- additional binds that aren't for "accept". Not calling + -- with nil (no action) can cause issues, for example with + -- dressing.nvim (#1014) + on_choice(nil, nil) + end end if opts.post_action_cb then