feat(fzf): better layout for code actions

This commit is contained in:
Folke Lemaitre
2024-06-13 13:05:16 +02:00
parent 8346fa7ddc
commit e948435f17

View File

@ -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,