7575--- @private
7676--- @return integer
7777function Render :icon ()
78+ local icon , highlight = self .data .icon , { self .data .foreground , self .data .background }
79+
7880 if not self .data .atx then
79- if self . data . icon == nil then
81+ if icon == nil then
8082 return 0
8183 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
8995 end
9096
9197 -- For atx headings available width is level + 1 - concealed, where level = number of
9298 -- `#` characters, one is added to account for the space after the last `#` but before
9399 -- the heading title, and concealed text is subtracted since that space is not usable
94100 local width = self .data .level + 1 - self .context :concealed (self .info )
95- if self . data . icon == nil then
101+ if icon == nil then
96102 return width
97103 end
98104
99- local padding = width - str .width (self . data . icon )
105+ local padding = width - str .width (icon )
100106 if self .heading .position == ' inline' or padding < 0 then
101107 local added = self .marks :add (true , self .info .start_row , self .info .start_col , {
102108 end_row = self .info .end_row ,
103109 end_col = self .info .end_col ,
104- virt_text = { { self . data . icon , { self . data . foreground , self . data . background } } },
110+ virt_text = { { icon , highlight } },
105111 virt_text_pos = ' inline' ,
106112 conceal = ' ' ,
107113 })
108- return added and str .width (self . data . icon ) or width
114+ return added and str .width (icon ) or width
109115 else
110116 self .marks :add (true , self .info .start_row , self .info .start_col , {
111117 end_row = self .info .end_row ,
112118 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 } },
114120 virt_text_pos = ' overlay' ,
115121 })
116122 return width
@@ -122,16 +128,13 @@ end
122128--- @return integer
123129function Render :width (icon_width )
124130 if self .data .heading_width == ' block' then
125- local width = nil
131+ local content_width = nil
126132 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' ))
128134 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 ()))
133136 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
135138 return math.max (width , self .heading .min_width )
136139 else
137140 return self .context :get_width ()
0 commit comments