From e948435f17afbbccfe1e7f2b355977efce9f1ff8 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 13 Jun 2024 13:05:16 +0200 Subject: [PATCH] feat(fzf): better layout for code actions --- lua/lazyvim/plugins/extras/editor/fzf.lua | 26 ++++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lua/lazyvim/plugins/extras/editor/fzf.lua b/lua/lazyvim/plugins/extras/editor/fzf.lua index 2a5f28c4..ada0f0ad 100644 --- a/lua/lazyvim/plugins/extras/editor/fzf.lua +++ b/lua/lazyvim/plugins/extras/editor/fzf.lua @@ -87,18 +87,28 @@ return { }, -- Custom LazyVim option to configure vim.ui.select ui_select = function(fzf_opts, items) - local title = vim.trim((fzf_opts.prompt or "Select"):gsub("%s*:%s*$", "")) - local width, height ---@type number?, number? - if fzf_opts.kind ~= "codeaction" then - width, height = 0.5, math.floor(math.min(vim.o.lines * 0.8, #items + 2) + 0.5) - end return vim.tbl_deep_extend("force", fzf_opts, { prompt = " ", winopts = { - title = " " .. title .. " ", + title = " " .. vim.trim((fzf_opts.prompt or "Select"):gsub("%s*:%s*$", "")) .. " ", title_pos = "center", - width = width, - height = height, + }, + }, fzf_opts.kind == "codeaction" and { + winopts = { + layout = "vertical", + -- height is number of items minus 15 lines for the preview, with a max of 80% screen height + height = math.floor(math.min(vim.o.lines * 0.8 - 16, #items + 2) + 0.5) + 16, + width = 0.5, + preview = { + layout = "vertical", + vertical = "down:15,border-top", + }, + }, + } or { + winopts = { + width = 0.5, + -- height is number of items, with a max of 80% screen height + height = math.floor(math.min(vim.o.lines * 0.8, #items + 2) + 0.5), }, }) end,