@@ -41,10 +41,12 @@ function renderer.draw_highlights(rendered, bufnr, ns, line_number)
41
41
end
42
42
end
43
43
44
- --- @param strings string[]
45
- --- @param max_width ? number
46
- --- @return blink.cmp.StringsBuild
47
- function renderer .build_strings (strings , max_width )
44
+ --- Gets the concatenated text and length for a list of strings
45
+ --- and truncates if necessary when max_width is set
46
+ --- @param strings string[]
47
+ --- @param max_width ? number
48
+ --- @return blink.cmp.StringsBuild
49
+ function renderer .concat_strings (strings , max_width )
48
50
local text = ' '
49
51
for _ , component in ipairs (strings ) do
50
52
text = text .. component
@@ -67,20 +69,20 @@ function renderer.render(components, lengths)
67
69
text = text .. component
68
70
offset = offset + # component
69
71
else
70
- local build = renderer .build_strings (component , component .max_width )
72
+ local concatenated = renderer .concat_strings (component , component .max_width )
71
73
72
74
table.insert (highlights , {
73
75
start = offset + 1 ,
74
- stop = offset + # build .text + 1 ,
76
+ stop = offset + # concatenated .text + 1 ,
75
77
group = component .hl_group ,
76
78
params = component .hl_params ,
77
79
})
78
80
79
- text = text .. build .text
80
- offset = offset + # build .text
81
+ text = text .. concatenated .text
82
+ offset = offset + # concatenated .text
81
83
82
84
if component .fill then
83
- local spaces = lengths [i ] - build .length
85
+ local spaces = lengths [i ] - concatenated .length
84
86
text = text .. string.rep (' ' , spaces )
85
87
offset = offset + spaces
86
88
end
@@ -96,21 +98,27 @@ function renderer.get_length(component)
96
98
if type (component ) == ' string' then
97
99
return vim .api .nvim_strwidth (component )
98
100
else
99
- local build = renderer .build_strings (component , component .max_width )
101
+ local build = renderer .concat_strings (component , component .max_width )
100
102
return build .length
101
103
end
102
104
end
103
105
104
106
--- @param components_list (blink.cmp.Component | string )[][]
107
+ --- @param min_width number
105
108
--- @return number[]
106
- function renderer .get_max_lengths (components_list )
109
+ function renderer .get_max_lengths (components_list , min_width )
107
110
local lengths = {}
108
111
for _ , components in ipairs (components_list ) do
109
112
for i , component in ipairs (components ) do
110
113
local length = renderer .get_length (component )
111
114
if not lengths [i ] or lengths [i ] < length then lengths [i ] = length end
112
115
end
113
116
end
117
+
118
+ for i , length in ipairs (lengths ) do
119
+ if length < min_width then lengths [i ] = min_width end
120
+ end
121
+
114
122
return lengths
115
123
end
116
124
0 commit comments