Skip to content

Commit 494af9d

Browse files
committed
fix(reload): update last_query (closes #1903)
1 parent 0c04031 commit 494af9d

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

lua/fzf-lua/core.lua

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,10 +1196,30 @@ M.convert_reload_actions = function(reload_cmd, opts)
11961196
if type(v) == "table" and v.reload then
11971197
-- Modified actions should not be considered in `actions.expect`
11981198
opts.actions[k]._ignore = true
1199+
-- Use both {q} and {+} as field indexes so we can update last query when
1200+
-- executing the action, without this we lose the last query on "hide" as
1201+
-- the process never terminates and `--print-query` isn't being printed
1202+
-- When no entry selected (with {q} {+}), {+} will be forced expand to ''
1203+
-- Use {n} to know if we really select an empty string, or there's just no selected
1204+
local field_index = v.field_index == false and "" or v.field_index or "{q} {n} {+}"
1205+
if not field_index:match("^{q} {n}") then
1206+
field_index = "{q} {n} " .. field_index
1207+
end
11991208
-- replace the action with shell cmd proxy to the original action
12001209
local shell_action = shell.raw_action(function(items, _, _)
1210+
if field_index:match("^{q} {n}") then
1211+
local query = table.remove(items, 1)
1212+
config.resume_set("query", query, opts)
1213+
local idx = table.remove(items, 1)
1214+
-- When no item is matching (empty list or non-matching query)
1215+
-- both {n} and {+} are expanded to "".
1216+
-- NOTE1: older versions of fzf don't expand {n} to "" (without match)
1217+
-- in such case the (empty) items table will be in `items[2]` (#1833)
1218+
-- NOTE2: on Windows, no match {n} is expanded to '' (#1836)
1219+
items = not tonumber(idx) and {} or items
1220+
end
12011221
v.fn(items, opts)
1202-
end, v.field_index == false and "" or v.field_index or "{+}", opts.debug)
1222+
end, field_index, opts.debug)
12031223
if type(v.prefix) == "string" and not v.prefix:match("%+$") then
12041224
v.prefix = v.prefix .. "+"
12051225
end

0 commit comments

Comments
 (0)