Skip to content

Commit 091bcd0

Browse files
phanenibhagwan
authored andcommitted
fix: vim.cmd.drop in actions
1 parent 96dede0 commit 091bcd0

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

lua/fzf-lua/actions.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ M.vimcmd_entry = function(_vimcmd, selected, opts)
177177
end
178178
if vimcmd then
179179
local cmd, is_buf_edit = vimcmd:gsub("|?%s-<auto>$", "")
180+
local res = vim.F.npcall(vim.api.nvim_parse_cmd, cmd, {}) or {}
181+
local need_args = (res.nargs == "+" or res.nargs == "1") and (not res.args or #res.args == 0)
182+
if need_args then
183+
return vim.cmd[res.cmd](require("fzf-lua.path").entry_to_file(sel, opts).path)
184+
end
180185
-- Command could have been "<auto>", in which case do nothing
181186
-- as we only have to load the buffer into the current window
182187
if #cmd > 0 then vim.cmd(cmd) end

tests/actions_spec.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,22 @@ T["actions"]["reload"] = new_set({
6161
end
6262
})
6363

64+
65+
T["actions"]["vimcmd"] = new_set()
66+
67+
T["actions"]["vimcmd"]["drop"] = function()
68+
helpers.FzfLua.files(child, {
69+
__abort_key = "<c-a>",
70+
__expect_lines = false,
71+
__after_open = function()
72+
if helpers.IS_WIN() then vim.uv.sleep(250) end
73+
end,
74+
query = "README.md$",
75+
actions = {
76+
["ctrl-a"] = function(...) require("fzf-lua.actions").vimcmd_entry("drop", ...) end,
77+
},
78+
})
79+
eq("README.md", vim.fs.basename(child.api.nvim_buf_get_name(0)))
80+
end
81+
6482
return T

0 commit comments

Comments
 (0)