-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(profiles): added
hide
(improved resume, #1686)
The profile changes the default binds to hide the fzf-lua window instead of aborting it, therefore keeping cursor position, selection, etc. Note that this also continues long running operations in the background so be mindful of sending fzf to background on a large mono repo, can still be aborted with `ctrl-c` or `alt-esc`. Enable with: ```lua -- Set as base profile :lua require("fzf-lua").setup({"hide"}) -- More than one profile :lua require("fzf-lua").setup({"border-fused","hide"}) -- Or with `profiles`: :FzfLua profiles load=hide -- More than one profile :FzfLua profiles load={"border-fused","hide"} ```
- Loading branch information
Showing
12 changed files
with
146 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
local uv = vim.uv or vim.loop | ||
local fzf = require("fzf-lua") | ||
return { | ||
desc = "hide interface instead of abort", | ||
defaults = { | ||
enrich = function(opts) | ||
if opts._is_fzf_tmux then | ||
fzf.utils.warn("'hide' profile cannot work with tmux, ignoring.") | ||
return opts | ||
end | ||
-- `execute-silent` actions are bugged with skim | ||
if fzf.utils.has(opts, "sk") then | ||
opts.actions["esc"] = false | ||
opts.keymap.builtin["<esc>"] = "hide" | ||
return opts | ||
end | ||
-- While we can use `keymap.builtin.<esc>` (to hide) this is better | ||
-- as it captures the query when execute-silent action is called as | ||
-- we add "{q}" as the first field index similar to `--print-query` | ||
local histfile = opts.fzf_opts and opts.fzf_opts["--history"] | ||
opts.actions["esc"] = { fn = fzf.actions.dummy_abort, desc = "hide" } | ||
opts.actions = vim.tbl_map(function(act) | ||
act = type(act) == "function" and { fn = act } or act | ||
act = type(act) == "table" and type(act[1]) == "function" | ||
and { fn = act[1], noclose = true } or act | ||
assert(type(act) == "table" and type(act.fn) == "function" or not act) | ||
if type(act) == "table" and | ||
not act.exec_silent and not act.reload and not act.noclose | ||
then | ||
local fn = act.fn | ||
act.exec_silent = true | ||
act.desc = act.desc or fzf.config.get_action_helpstr(fn) | ||
act.fn = function(s, o) | ||
fzf.hide() | ||
fn(s, o) | ||
if histfile and type(o.last_query) == "string" and #o.last_query > 0 then | ||
local fd = uv.fs_open(histfile, "a", -1) | ||
if fd then | ||
uv.fs_write(fd, o.last_query .. "\n", nil, function(_) | ||
uv.fs_close(fd) | ||
end) | ||
end | ||
end | ||
end | ||
end | ||
return act | ||
end, opts.actions) | ||
return opts | ||
end, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.