From 86804f7462301718e83397cc282d95b9f898589d Mon Sep 17 00:00:00 2001 From: bhagwan Date: Mon, 13 Jun 2022 10:48:11 -0700 Subject: [PATCH] feat(actions): do not require 'default' action (#449) --- lua/fzf-lua/actions.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lua/fzf-lua/actions.lua b/lua/fzf-lua/actions.lua index 962e433..b974610 100644 --- a/lua/fzf-lua/actions.lua +++ b/lua/fzf-lua/actions.lua @@ -24,15 +24,18 @@ end M.normalize_selected = function(actions, selected) -- 1. If there are no additional actions but the default -- the selected table will contain the selected item(s) - -- 2. If multiple actions where defined the first item - -- will contain the action keybind string + -- 2. If at least one non-default action was defined, our 'expect' + -- function above sent fzf the '--expect` flag, from `man fzf`: + -- When this option is set, fzf will print the name of + -- the key pressed as the first line of its output (or + -- as the second line if --print-query is also used). -- -- The below makes separates the keybind from the item(s) -- and makes sure 'selected' contains only items or {} -- so it can always be enumerated safely if not actions or not selected then return end local action = _default_action - if utils.tbl_length(actions)>1 then + if utils.tbl_length(actions)>1 or not actions[_default_action] then -- keybind should be in item #1 -- default keybind is an empty string -- so we leave that as "default" @@ -62,9 +65,9 @@ M.act = function(actions, selected, opts) action(entries, opts) elseif type(action) == 'string' then vim.cmd(action) - else + elseif keybind ~= _default_action then utils.warn(("unsupported action: '%s', type:%s") - :format(action, type(action))) + :format(keybind, type(action))) end end