Skip to content

Commit f579824

Browse files
phanenibhagwan
authored andcommitted
fix(hide): actions should be nop when nothing match
Regression from f0e830e e.g. `FzfLua files query=nothing` then `<c-t>` should not open new tab fix: opts.__pid -> opts.PidObject
1 parent 6c4632c commit f579824

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

lua/fzf-lua/core.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,9 @@ M.fzf = function(contents, opts)
392392
-- NOTE: might be an overkill since we're using $FZF_DEFAULT_COMMAND
393393
-- to spawn the piped process and fzf is responsible for termination
394394
-- when the fzf process exists
395-
if tonumber(opts.__pid) then
396-
libuv.process_kill(opts.__pid)
395+
if opts.PidObject then
396+
libuv.process_kill(opts.PidObject:get())
397+
opts.PidObject:set(nil)
397398
end
398399
-- If a hidden process was killed by [re-]starting a new picker do nothing
399400
if fzf_win:was_hidden() then return nil, nil end

lua/fzf-lua/shell.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,6 @@ end
489489
---@param field_index string
490490
---@return string
491491
M.stringify_data2 = function(fn, opts, field_index)
492-
local field_index0 = field_index
493492
local did_override = false
494493
if not field_index:match("{q} {n}$") then
495494
field_index = field_index .. " {q} {n}"
@@ -506,7 +505,7 @@ M.stringify_data2 = function(fn, opts, field_index)
506505
-- fix side effect of "{q} {+}": {+} is forced expanded to ""
507506
-- only when field_index is empty (otherwise it can be complex/unpredictable)
508507
-- {n} used to determine if "zero-selected && zero-match", then patch: "" -> nil
509-
if #field_index0 == 0 then
508+
if field_index == "{+} {q} {n}" then
510509
-- When no item is matching (empty list or non-matching query)
511510
-- both {n} and {+} are expanded to "".
512511
-- NOTE1: older versions of fzf don't expand {n} to "" (without match)

tests/files_spec.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ T["files"]["previewer"]["builtin"] = new_set({ parametrize = { { "ci" }, { "buil
8787
-- Verify previewer "last_entry" was set
8888
child.type_keys("<c-j>")
8989
child.wait_until(function()
90-
return child.lua_get([[FzfLua.utils.fzf_winobj()._previewer.last_entry]]) ==
90+
return exec_lua([[return FzfLua.utils.fzf_winobj()._previewer.last_entry]]) ==
9191
(icons and " LICENSE" or "LICENSE")
9292
end)
9393
end,
@@ -187,4 +187,16 @@ T["files"]["preview should work after chdir #1864"] = function()
187187
})
188188
end
189189

190+
T["files"]["nop on nothing match"] = function()
191+
reload({ "hide" })
192+
local ctx = exec_lua([[return FzfLua.utils.CTX()]])
193+
for _, key in ipairs({ "<cr>", "<c-t>" }) do
194+
exec_lua([[FzfLua.files { query = ("%s is nop on nothing match"):format(...) }]], { key })
195+
child.wait_until(function() return exec_lua([[return _G._fzf_load_called]]) == true end)
196+
child.type_keys(key)
197+
child.wait_until(function() return exec_lua([[return _G._fzf_lua_on_create]]) == vim.NIL end)
198+
eq(ctx, exec_lua([[return FzfLua.utils.CTX()]]))
199+
end
200+
end
201+
190202
return T

0 commit comments

Comments
 (0)