Skip to content

Commit

Permalink
fix: better support fzf flags -1|--select-1 (#1589)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed Dec 18, 2024
1 parent d51d933 commit 1fd9c17
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lua/fzf-lua/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ M.normalize_selected = function(actions, selected, opts)
-- and makes sure 'selected' contains only item(s) or {}
-- so it can always be enumerated safely
if not actions or not selected then return end
if opts.__FZF_VERSION and opts.__FZF_VERSION >= 0.53 then
if opts.__FZF_VERSION and opts.__FZF_VERSION >= 0.53
or opts.__SK_VERSION and opts.__SK_VERSION >= 0.14 then
-- Using the new `print` action keybind is expected at `selected[1]`
-- NOTE: if `--select-1|-q` was used we'll be missing the keybind
-- since `-1` triggers "accept" assume "enter" (#1589)
if selected and #selected == 1 then
table.insert(selected, 1, "enter")
end
local entries = vim.deepcopy(selected)
local keybind = table.remove(entries, 1)
return keybind, entries
Expand Down
5 changes: 3 additions & 2 deletions lua/fzf-lua/fzf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,15 @@ function M.raw_fzf(contents, fzf_cli_args, opts)
-- from FZF_DEFAULT_OPTS (#1107)
local default_opts = os.getenv("FZF_DEFAULT_OPTS")
if not default_opts then return end
local flags = { "--select-1", "-1" }
local patterns = { "--preview-window" }
for _, p in ipairs(patterns) do
-- remove flag end of string
default_opts = default_opts:gsub(utils.lua_regex_escape(p) .. "[=%s]+[^%-]+%s-$", "")
-- remove flag start/mid of string
default_opts = default_opts:gsub(utils.lua_regex_escape(p) .. "[=%s]+.-%s+%-%-", " --")
end
-- NOTE: better support for this via `actions.normalize_selected`
--[[ local flags = { "--select-1", "-1" }
for _, p in ipairs(flags) do
local escaped = utils.lua_regex_escape(p)
repeat
Expand All @@ -267,7 +268,7 @@ function M.raw_fzf(contents, fzf_cli_args, opts)
default_opts = default_opts:gsub(string.format("%s%s%s", before, escaped, after), "")
end
until not has_opt
end
end ]]
return default_opts
end)(),
-- Nullify user's RG config as this can cause conflicts
Expand Down

0 comments on commit 1fd9c17

Please sign in to comment.