@@ -119,73 +119,76 @@ end
119119--- @return integer
120120function Render :marker ()
121121 local icon = self .data .icon
122+ local position = self .config .position
122123 local highlight = {} --- @type string[]
123- if self .data .fg then
124- highlight [# highlight + 1 ] = self .data .fg
125- end
126- if self .data .bg then
127- highlight [# highlight + 1 ] = self .data .bg
128- end
124+ highlight [# highlight + 1 ] = self .data .fg
125+ highlight [# highlight + 1 ] = self .data .bg
126+
129127 if self .data .atx then
130128 local node = self .data .marker
131- -- add 1 to account for space after last '#'
129+
130+ -- add 1 to right to account for space after last '#'
132131 local width = self .context :width (node ) + 1
132+ local offset = { 0 , 0 , 0 , 1 } --- @type Range4
133+
133134 if not icon or # highlight == 0 then
134135 return width
135136 end
136- if self .config .position == ' right' then
137- self .marks :over (self .config , true , node , {
138- conceal = ' ' ,
139- }, { 0 , 0 , 0 , 1 })
137+
138+ if position == ' eol' or position == ' right' then
139+ self .marks :over (self .config , true , node , { conceal = ' ' }, offset )
140140 self .marks :start (self .config , ' head_icon' , node , {
141141 priority = 1000 ,
142142 virt_text = { { icon , highlight } },
143- virt_text_pos = ' eol' ,
143+ virt_text_pos = position == ' eol' and ' eol_right_align'
144+ or ' eol' ,
144145 })
145- return 1 + str .width (icon )
146- else
147- local padding = width - str .width (icon )
148- if self .config .position == ' inline' or padding < 0 then
149- local added = self .marks :over (self .config , ' head_icon' , node , {
150- virt_text = { { icon , highlight } },
151- virt_text_pos = ' inline' ,
152- conceal = ' ' ,
153- }, { 0 , 0 , 0 , 1 })
154- return added and str .width (icon ) or width
155- else
156- self .marks :over (self .config , ' head_icon' , node , {
157- virt_text = { { str .pad (padding ) .. icon , highlight } },
158- virt_text_pos = ' overlay' ,
159- })
160- return width
161- end
146+ return position == ' eol' and 0 or 1 + str .width (icon )
147+ end
148+
149+ local space = width - str .width (icon )
150+ if position == ' inline' or space < 0 then
151+ local added = self .marks :over (self .config , ' head_icon' , node , {
152+ virt_text = { { icon , highlight } },
153+ virt_text_pos = ' inline' ,
154+ conceal = ' ' ,
155+ }, offset )
156+ return added and str .width (icon ) or width
162157 end
158+
159+ self .marks :over (self .config , ' head_icon' , node , {
160+ virt_text = { { str .pad (space ) .. icon , highlight } },
161+ virt_text_pos = ' overlay' ,
162+ })
163+ return width
163164 else
164165 local node = self .node
166+
165167 if not icon or # highlight == 0 then
166168 return 0
167169 end
168- if self .config .position == ' right' then
170+
171+ if position == ' eol' or position == ' right' then
169172 self .marks :start (self .config , ' head_icon' , node , {
170173 priority = 1000 ,
171174 virt_text = { { icon , highlight } },
172- virt_text_pos = ' eol' ,
175+ virt_text_pos = position == ' eol' and ' eol_right_align'
176+ or ' eol' ,
177+ })
178+ return position == ' eol' and 0 or 1 + str .width (icon )
179+ end
180+
181+ local added = self .marks :start (self .config , ' head_icon' , node , {
182+ virt_text = { { icon , highlight } },
183+ virt_text_pos = ' inline' ,
184+ })
185+ for row = node .start_row + 1 , node .end_row - 1 do
186+ self .marks :add (self .config , ' head_icon' , row , node .start_col , {
187+ virt_text = { { str .pad (str .width (icon )), highlight } },
188+ virt_text_pos = ' inline' ,
173189 })
174- return 1 + str .width (icon )
175- else
176- local col = node .start_col
177- local added = true
178- for row = node .start_row , node .end_row - 1 do
179- local start = row == node .start_row
180- local text = start and icon or str .pad (str .width (icon ))
181- added = added
182- and self .marks :add (self .config , ' head_icon' , row , col , {
183- virt_text = { { text , highlight } },
184- virt_text_pos = ' inline' ,
185- })
186- end
187- return added and str .width (icon ) or 0
188190 end
191+ return added and str .width (icon ) or 0
189192 end
190193end
191194
0 commit comments