@@ -153,22 +153,20 @@ return {
153
153
" hrsh7th/nvim-cmp" ,
154
154
opts = function (_ , opts )
155
155
local astrocore , astroui = require " astrocore" , require " astroui"
156
+ local function truncate (str , len )
157
+ if not str then return end
158
+ local truncated = vim .fn .strcharpart (str , 0 , len )
159
+ return truncated == str and str or truncated .. astroui .get_icon " Ellipsis"
160
+ end
161
+
156
162
if not opts .formatting then opts .formatting = {} end
157
163
opts .formatting .format = astrocore .patch_func (opts .formatting .format , function (format , ...)
158
164
-- get item from original formatting function
159
165
local vim_item = format (... )
160
166
161
- -- truncate label to maximum of 25% of the window
162
- local label = vim_item .abbr
163
- local truncated_label = vim .fn .strcharpart (label , 0 , math.floor (0.25 * vim .o .columns ))
164
- if truncated_label ~= label then vim_item .abbr = truncated_label .. astroui .get_icon " Ellipsis" end
165
-
166
- -- truncate menu to maximum of 25% of the window
167
- if vim_item .menu then
168
- local menu = vim_item .menu
169
- local truncated_menu = vim .fn .strcharpart (menu , 0 , math.floor (0.25 * vim .o .columns ))
170
- if truncated_menu ~= menu then vim_item .menu = truncated_menu .. astroui .get_icon " Ellipsis" end
171
- end
167
+ -- truncate text fields to maximum of 25% of the window
168
+ vim_item .abbr = truncate (vim_item .abbr , math.floor (0.25 * vim .o .columns ))
169
+ vim_item .menu = truncate (vim_item .menu , math.floor (0.25 * vim .o .columns ))
172
170
173
171
return vim_item
174
172
end )
0 commit comments