75
75
--- @private
76
76
--- @return integer
77
77
function Render :icon ()
78
+ local icon , highlight = self .data .icon , { self .data .foreground , self .data .background }
79
+
78
80
if not self .data .atx then
79
- if self . data . icon == nil then
81
+ if icon == nil then
80
82
return 0
81
83
end
82
- local added = self .marks :add (true , self .info .start_row , self .info .start_col , {
83
- end_row = self .info .end_row ,
84
- end_col = self .info .end_col ,
85
- virt_text = { { self .data .icon , { self .data .foreground , self .data .background } } },
86
- virt_text_pos = ' inline' ,
87
- })
88
- return added and str .width (self .data .icon ) or 0
84
+ local added = true
85
+ for row = self .info .start_row , self .data .end_row - 1 do
86
+ added = added
87
+ and self .marks :add (true , row , self .info .start_col , {
88
+ end_row = row ,
89
+ end_col = self .info .end_col ,
90
+ virt_text = { { row == self .info .start_row and icon or str .pad (str .width (icon )), highlight } },
91
+ virt_text_pos = ' inline' ,
92
+ })
93
+ end
94
+ return added and str .width (icon ) or 0
89
95
end
90
96
91
97
-- For atx headings available width is level + 1 - concealed, where level = number of
92
98
-- `#` characters, one is added to account for the space after the last `#` but before
93
99
-- the heading title, and concealed text is subtracted since that space is not usable
94
100
local width = self .data .level + 1 - self .context :concealed (self .info )
95
- if self . data . icon == nil then
101
+ if icon == nil then
96
102
return width
97
103
end
98
104
99
- local padding = width - str .width (self . data . icon )
105
+ local padding = width - str .width (icon )
100
106
if self .heading .position == ' inline' or padding < 0 then
101
107
local added = self .marks :add (true , self .info .start_row , self .info .start_col , {
102
108
end_row = self .info .end_row ,
103
109
end_col = self .info .end_col ,
104
- virt_text = { { self . data . icon , { self . data . foreground , self . data . background } } },
110
+ virt_text = { { icon , highlight } },
105
111
virt_text_pos = ' inline' ,
106
112
conceal = ' ' ,
107
113
})
108
- return added and str .width (self . data . icon ) or width
114
+ return added and str .width (icon ) or width
109
115
else
110
116
self .marks :add (true , self .info .start_row , self .info .start_col , {
111
117
end_row = self .info .end_row ,
112
118
end_col = self .info .end_col ,
113
- virt_text = { { str .pad (padding ) .. self . data . icon , { self . data . foreground , self . data . background } } },
119
+ virt_text = { { str .pad (padding ) .. icon , highlight } },
114
120
virt_text_pos = ' overlay' ,
115
121
})
116
122
return width
@@ -122,16 +128,13 @@ end
122
128
--- @return integer
123
129
function Render :width (icon_width )
124
130
if self .data .heading_width == ' block' then
125
- local width = nil
131
+ local content_width = nil
126
132
if self .data .atx then
127
- width = icon_width + self .context :width (self .info :sibling (' inline' ))
133
+ content_width = self .context :width (self .info :sibling (' inline' ))
128
134
else
129
- -- Account for icon in first row
130
- local widths = vim .tbl_map (str .width , self .info :lines ())
131
- widths [1 ] = widths [1 ] + icon_width
132
- width = vim .fn .max (widths )
135
+ content_width = vim .fn .max (vim .tbl_map (str .width , self .info :lines ()))
133
136
end
134
- width = self .heading .left_pad + width + self .heading .right_pad
137
+ local width = self .heading .left_pad + icon_width + content_width + self .heading .right_pad
135
138
return math.max (width , self .heading .min_width )
136
139
else
137
140
return self .context :get_width ()
0 commit comments