3
3
--- @field gap number
4
4
--- @field lines string[][]
5
5
--- @field width number
6
- --- @field ctxs blink.cmp.CompletionRenderContext []
6
+ --- @field ctxs blink.cmp.DrawItemContext []
7
7
---
8
8
--- @field new fun ( components : blink.cmp.DrawComponent[] , gap : number ): blink.cmp.DrawColumn
9
9
--- @field render fun ( self : blink.cmp.DrawColumn , ctxs : blink.cmp.DrawItemContext[] )
10
- --- @field get_line_text fun ( self : blink.cmp.DrawColumn , line_idx : number ): string[]
10
+ --- @field get_line_text fun ( self : blink.cmp.DrawColumn , line_idx : number ): string
11
11
--- @field get_line_highlights fun ( self : blink.cmp.DrawColumn , line_idx : number ): blink.cmp.DrawHighlight[]
12
12
13
13
local text_lib = require (' blink.cmp.windows.render.text' )
@@ -46,9 +46,9 @@ function column:render(ctxs)
46
46
--- get the total width of the column
47
47
local column_width = 0
48
48
for _ , max_component_width in ipairs (max_component_widths ) do
49
- column_width = column_width + max_component_width
49
+ if max_component_width > 0 then column_width = column_width + max_component_width + self . gap end
50
50
end
51
- column_width = column_width + self .gap * ( # self . components - 1 )
51
+ column_width = math.max ( column_width - self .gap , 0 )
52
52
53
53
--- find the component that will fill the empty space
54
54
local fill_idx = - 1
@@ -63,9 +63,10 @@ function column:render(ctxs)
63
63
--- and add extra spaces until we reach the column width
64
64
for _ , line in ipairs (lines ) do
65
65
local line_width = 0
66
- for idx , component_text in ipairs (line ) do
67
- line_width = line_width + vim .api .nvim_strwidth (component_text ) + ( idx == # line and 0 or self .gap )
66
+ for _ , component_text in ipairs (line ) do
67
+ if # component_text > 0 then line_width = line_width + vim .api .nvim_strwidth (component_text ) + self .gap end
68
68
end
69
+ line_width = line_width - self .gap
69
70
local remaining_width = column_width - line_width
70
71
line [fill_idx ] = text_lib .pad (line [fill_idx ], vim .api .nvim_strwidth (line [fill_idx ]) + remaining_width )
71
72
end
@@ -77,12 +78,12 @@ function column:render(ctxs)
77
78
end
78
79
79
80
function column :get_line_text (line_idx )
81
+ local text = ' '
80
82
local line = self .lines [line_idx ]
81
- local concatenated = ' '
82
- for idx , component in ipairs (line ) do
83
- concatenated = concatenated .. component .. string.rep (' ' , idx == # line and 0 or self .gap )
83
+ for _ , component in ipairs (line ) do
84
+ if # component > 0 then text = text .. component .. string.rep (' ' , self .gap ) end
84
85
end
85
- return concatenated
86
+ return text : sub ( 1 , - self . gap - 1 )
86
87
end
87
88
88
89
function column :get_line_highlights (line_idx )
@@ -92,24 +93,25 @@ function column:get_line_highlights(line_idx)
92
93
93
94
for component_idx , component in ipairs (self .components ) do
94
95
local text = self .lines [line_idx ][component_idx ]
95
-
96
- local column_highlights = type (component .highlight ) == ' function' and component .highlight (ctx , text )
97
- or component .highlight
98
-
99
- if type (column_highlights ) == ' string' then
100
- table.insert (highlights , { offset , offset + # text , group = column_highlights })
101
- elseif type (column_highlights ) == ' table' then
102
- for _ , highlight in ipairs (column_highlights ) do
103
- table.insert (highlights , {
104
- offset + highlight [1 ],
105
- offset + highlight [2 ],
106
- group = highlight .group ,
107
- params = highlight .params ,
108
- })
96
+ if # text > 0 then
97
+ local column_highlights = type (component .highlight ) == ' function' and component .highlight (ctx , text )
98
+ or component .highlight
99
+
100
+ if type (column_highlights ) == ' string' then
101
+ table.insert (highlights , { offset , offset + # text , group = column_highlights })
102
+ elseif type (column_highlights ) == ' table' then
103
+ for _ , highlight in ipairs (column_highlights ) do
104
+ table.insert (highlights , {
105
+ offset + highlight [1 ],
106
+ offset + highlight [2 ],
107
+ group = highlight .group ,
108
+ params = highlight .params ,
109
+ })
110
+ end
109
111
end
110
- end
111
112
112
- offset = offset + # text + self .gap
113
+ offset = offset + # text + self .gap
114
+ end
113
115
end
114
116
115
117
return highlights
0 commit comments