Skip to content

Commit e68305d

Browse files
committed
fix(fn_transform): nil return filter (closes #2185)
1 parent 491b088 commit e68305d

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

lua/fzf-lua/shell.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,17 @@ M.stringify = function(contents, opts, fzf_field_index)
414414
if type(data) == "table" then
415415
-- cb_write_lines was sent instead of cb_lines
416416
if fn_transform then
417-
data = vim.tbl_map(function(x) return fn_transform(x, opts) end, data)
417+
-- Iterate back to front so we can remove items safely
418+
for i = #data, 1, -1 do
419+
local v = fn_transform(data[i], opts)
420+
if not v then
421+
table.remove(data, i)
422+
else
423+
data[i] = v
424+
end
425+
end
418426
end
419-
data = table.concat(data, EOL) .. EOL
427+
data = #data > 0 and (table.concat(data, EOL) .. EOL) or ""
420428
end
421429
uv.write(pipe, tostring(data), function(err)
422430
write_cb_count = write_cb_count - 1

0 commit comments

Comments
 (0)