@@ -51,13 +51,20 @@ export function getLineDecorationGutterChildren(
5151 return undefined ;
5252 }
5353
54+ const visualBarLayers = collapseBarLayersForRendering ( barLayers ) ;
55+
5456 return [
5557 createHastElement ( {
5658 tagName : 'span' ,
5759 properties : {
5860 'data-decoration-bar-stack' : '' ,
59- 'data-decoration-bar-layer-count' : String ( barLayers . length ) ,
60- style : getLineDecorationBarStackStyle ( barLayers ) ,
61+ 'data-decoration-bar-layer-count' : String ( visualBarLayers . length ) ,
62+ 'data-decoration-bar-overlap' :
63+ visualBarLayers . length > 1 ? '' : undefined ,
64+ 'data-decoration-bar-second' :
65+ visualBarLayers . length > 1 ? '' : undefined ,
66+ 'data-decoration-bar-third' :
67+ visualBarLayers . length > 2 ? '' : undefined ,
6168 } ,
6269 } ) ,
6370 ] ;
@@ -131,6 +138,12 @@ export function mergeNormalizedLineDecorations(
131138 second . barLayers
132139 ) ;
133140 const topBar = barLayers ?. at ( - 1 ) ;
141+ const topBarDepth =
142+ topBar ?. sourceIndex === first . barSourceIndex
143+ ? first . barDepth
144+ : topBar ?. sourceIndex === second . barSourceIndex
145+ ? second . barDepth
146+ : undefined ;
134147
135148 return {
136149 barIndices,
@@ -143,7 +156,7 @@ export function mergeNormalizedLineDecorations(
143156 backgroundColor : background ?. color ,
144157 backgroundLineNumber : background ?. lineNumber ,
145158 backgroundSourceIndex : background ?. sourceIndex ,
146- barDepth : mergeDecorationDepth ( first . barDepth , second . barDepth ) ,
159+ barDepth : topBarDepth ,
147160 barLayers,
148161 backgroundDepth : mergeDecorationDepth (
149162 first . backgroundDepth ,
@@ -155,6 +168,8 @@ export function mergeNormalizedLineDecorations(
155168function getLineDecorationBarProperties (
156169 decorations : NormalizedLineDecorations | undefined
157170) : Properties | undefined {
171+ const topmostBarEndIndices = getTopmostBarEndIndices ( decorations ) ;
172+
158173 return mergeHastProperties (
159174 mergeHastProperties (
160175 getLineDecorationProperties (
@@ -173,42 +188,45 @@ function getLineDecorationBarProperties(
173188 'data-decoration-bar-start' ,
174189 decorations ?. startIndices ,
175190 'data-decoration-bar-end' ,
176- decorations ?. endIndices
191+ topmostBarEndIndices
177192 )
178193 ) ;
179194}
180195
181- function getLineDecorationBarStackStyle ( barLayers : VisibleBarLayer [ ] ) : string {
182- const serializedLayers = [ ...barLayers ] . reverse ( ) ;
183- const styles = [
184- `--diffs-decoration-bar-layer-count:${ serializedLayers . length } ;` ,
185- ] ;
186-
187- for ( const [ index , layer ] of serializedLayers . entries ( ) ) {
188- const layerNumber = index + 1 ;
189- styles . push ( `--diffs-decoration-bar-color-${ layerNumber } :${ layer . color } ;` ) ;
190- styles . push (
191- `--diffs-decoration-bar-tier-${ layerNumber } :${ getBarVisualTier ( layerNumber ) } ;`
192- ) ;
193- styles . push (
194- `--diffs-decoration-bar-start-cap-${ layerNumber } :${ layer . showStartCap ? 1 : 0 } ;`
195- ) ;
196- styles . push (
197- `--diffs-decoration-bar-end-cap-${ layerNumber } :${ layer . showEndCap ? 1 : 0 } ;`
198- ) ;
196+ function getTopmostBarEndIndices (
197+ decorations : NormalizedLineDecorations | undefined
198+ ) : number [ ] | undefined {
199+ const topmostBarSourceIndex = decorations ?. barSourceIndex ;
200+ if ( topmostBarSourceIndex == null ) {
201+ return undefined ;
199202 }
200203
201- return styles . join ( '' ) ;
204+ return ( decorations ?. endIndices ?. includes ( topmostBarSourceIndex ) ?? false )
205+ ? [ topmostBarSourceIndex ]
206+ : undefined ;
202207}
203208
204- function getBarVisualTier ( layerNumber : number ) : 1 | 2 | 3 {
205- if ( layerNumber <= 1 ) {
206- return 1 ;
207- }
208- if ( layerNumber === 2 ) {
209- return 2 ;
209+ // When adjacent visible layers share the same bar color, render them as one
210+ // continuous visual bar so overlap identity does not create artificial gaps.
211+ function collapseBarLayersForRendering (
212+ barLayers : VisibleBarLayer [ ]
213+ ) : VisibleBarLayer [ ] {
214+ const serializedLayers = [ ...barLayers ] . reverse ( ) ;
215+ const collapsed : VisibleBarLayer [ ] = [ ] ;
216+
217+ for ( const layer of serializedLayers ) {
218+ const previousLayer = collapsed . at ( - 1 ) ;
219+ if ( previousLayer ?. color !== layer . color ) {
220+ collapsed . push ( { ...layer } ) ;
221+ continue ;
222+ }
223+
224+ previousLayer . showStartCap =
225+ previousLayer . showStartCap && layer . showStartCap ;
226+ previousLayer . showEndCap = previousLayer . showEndCap && layer . showEndCap ;
210227 }
211- return 3 ;
228+
229+ return collapsed . reverse ( ) ;
212230}
213231
214232function getLineDecorationProperties (
0 commit comments