refactor: loop

This commit is contained in:
Folke Lemaitre 2024-06-30 22:26:24 +02:00
parent bb123758d3
commit 8742b2b161
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -55,14 +55,15 @@ return {
item.kind = icons[item.kind] .. item.kind item.kind = icons[item.kind] .. item.kind
end end
local abbr_width = vim.g.cmp_widths and vim.g.cmp_widths.abbr or 30 local widths = {
local menu_width = vim.g.cmp_widths and vim.g.cmp_widths.menu or 30 abbr = vim.g.cmp_widths and vim.g.cmp_widths.abbr or 40,
menu = vim.g.cmp_widths and vim.g.cmp_widths.menu or 30,
}
if item.menu then for key, width in pairs(widths) do
if vim.fn.strdisplaywidth(item.abbr) > abbr_width then if item[key] and vim.fn.strdisplaywidth(item[key]) > width then
item.abbr = vim.fn.strcharpart(item.abbr, 0, abbr_width - 1) .. "" item[key] = vim.fn.strcharpart(item[key], 0, width - 1) .. ""
end end
item.menu = vim.fn.strcharpart(item.menu, 0, menu_width - 1) .. ""
end end
return item return item