From 0819f9396e94a4188522b6739ade3d6024d2b8a7 Mon Sep 17 00:00:00 2001 From: Iordanis Petkakis <12776461+dpetka2001@users.noreply.github.com> Date: Wed, 13 Nov 2024 20:20:48 +0200 Subject: [PATCH] fix(fzf): decouple `defaults` from `opts` to easy switch profiles (#4190) ## Description This decouples `defaults` from `opts`, so that if users switch to another profile they can take advantage of the profile's default settings and prompts. I use `default-title` either way. I just stumbled upon this when I tried the rest profiles and thought maybe there would be users who would prefer to have the default prompts if they chose another profile. ## Related Issue(s) No ## Screenshots ## Checklist - [x] I've read the [CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md) guidelines. --------- Co-authored-by: Folke Lemaitre --- lua/lazyvim/plugins/extras/editor/fzf.lua | 32 +++++++++++++---------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/lua/lazyvim/plugins/extras/editor/fzf.lua b/lua/lazyvim/plugins/extras/editor/fzf.lua index e23af81b..c70a6f14 100644 --- a/lua/lazyvim/plugins/extras/editor/fzf.lua +++ b/lua/lazyvim/plugins/extras/editor/fzf.lua @@ -74,18 +74,6 @@ return { config.defaults.actions.files["alt-c"] = config.defaults.actions.files["ctrl-r"] config.set_action_helpstr(config.defaults.actions.files["ctrl-r"], "toggle-root-dir") - -- use the same prompt for all - local defaults = require("fzf-lua.profiles.default-title") - local function fix(t) - t.prompt = t.prompt ~= nil and " " or nil - for _, v in pairs(t) do - if type(v) == "table" then - fix(v) - end - end - end - fix(defaults) - local img_previewer ---@type string[]? for _, v in ipairs({ { cmd = "ueberzug", args = {} }, @@ -98,7 +86,8 @@ return { end end - return vim.tbl_deep_extend("force", defaults, { + return { + "default-title", fzf_colors = true, fzf_opts = { ["--no-scrollbar"] = true, @@ -186,9 +175,24 @@ return { previewer = vim.fn.executable("delta") == 1 and "codeaction_native" or nil, }, }, - }) + } end, config = function(_, opts) + if opts[1] == "default-title" then + -- use the same prompt for all pickers for profile `default-title` and + -- profiles that use `default-title` as base profile + local function fix(t) + t.prompt = t.prompt ~= nil and " " or nil + for _, v in pairs(t) do + if type(v) == "table" then + fix(v) + end + end + return t + end + opts = vim.tbl_deep_extend("force", fix(require("fzf-lua.profiles.default-title")), opts) + opts[1] = nil + end require("fzf-lua").setup(opts) end, init = function()