Skip to content

Commit

Permalink
fix: toggle header when opts contain --no-ignore (closes #1021)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed Feb 1, 2024
1 parent 2518503 commit 718be95
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
3 changes: 0 additions & 3 deletions lua/fzf-lua/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -777,12 +777,9 @@ M.toggle_ignore = function(_, opts)
local cmd = opts._cmd or opts.cmd
if cmd:match(utils.lua_regex_escape(flag)) then
o.cmd = cmd:gsub(utils.lua_regex_escape(flag), "")
o._hdr_to = false
else
-- signals "core.set_header" to set the correct "to" header
local bin, args = cmd:match("([^%s]+)(.*)$")
o.cmd = string.format("%s%s%s", bin, flag, args)
o._hdr_to = true
end
opts.__call_fn(o)
end
Expand Down
45 changes: 33 additions & 12 deletions lua/fzf-lua/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,34 @@ local M = {}
M.ACTION_DEFINITIONS = {
-- list of supported actions with labels to be displayed in the headers
-- no pos implies an append to header array
[actions.toggle_ignore] = { "Disable .gitignore", fn_reload = "Respect .gitignore", _hdr_to = true },
[actions.grep_lgrep] = { "Regex Search", fn_reload = "Fuzzy Search" },
[actions.sym_lsym] = { "Live Query", fn_reload = "Fuzzy Search" },
[actions.toggle_ignore] = {
function(o)
local flag = o.toggle_ignore_flag or "--no-ignore"
if o.cmd:match(utils.lua_regex_escape(flag)) then
return "Respect .gitignore"
else
return "Disable .gitignore"
end
end,
},
[actions.grep_lgrep] = {
function(o)
if o.fn_reload then
return "Fuzzy Search"
else
return "Regex Search"
end
end,
},
[actions.sym_lsym] = {
function(o)
if o.fn_reload then
return "Fuzzy Search"
else
return "Live Query"
end
end,
},
[actions.buf_del] = { "close" },
[actions.arg_del] = { "delete" },
[actions.git_reset] = { "reset" },
Expand Down Expand Up @@ -744,21 +769,17 @@ M.set_header = function(opts, hdr_tbl)
actions = {
hdr_txt_opt = "interactive_header_txt",
hdr_txt_str = "",
val = function()
val = function(o)
if opts.no_header_i then return end
local defs = M.ACTION_DEFINITIONS
local ret = {}
for k, v in pairs(opts.actions) do
local action = type(v) == "function" and v or type(v) == "table" and (v.fn or v[1])
if type(action) == "function" and defs[action] then
local def = defs[action]
local to
if
not def._hdr_to and opts.fn_reload -- grep_lgrep|sym_lsym
or def._hdr_to and opts._hdr_to then -- toggle_ignore
to = def.fn_reload
else
to = def[1]
local to = def[1]
if type(to) == "function" then
to = to(o)
end
table.insert(ret, def.pos or #ret + 1,
string.format("<%s> to %s",
Expand Down Expand Up @@ -796,7 +817,7 @@ M.set_header = function(opts, hdr_tbl)
for _, h in ipairs(opts.headers) do
assert(definitions[h])
local def = definitions[h]
local txt = def.val()
local txt = def.val(opts)
if def and txt then
hdr_str = not hdr_str and "" or (hdr_str .. ", ")
hdr_str = ("%s%s%s"):format(hdr_str, def.hdr_txt_str,
Expand Down

0 comments on commit 718be95

Please sign in to comment.