@@ -50,6 +50,12 @@ import { getFiletypeFromFileName } from '../utils/getFiletypeFromFileName';
5050import { getHighlighterOptions } from '../utils/getHighlighterOptions' ;
5151import { getHunkSeparatorSlotName } from '../utils/getHunkSeparatorSlotName' ;
5252import { getLineAnnotationName } from '../utils/getLineAnnotationName' ;
53+ import {
54+ getLineDecorationContentProperties ,
55+ getLineDecorationGutterProperties ,
56+ mergeHastProperties ,
57+ mergeNormalizedLineDecorations ,
58+ } from '../utils/getLineDecorationProperties' ;
5359import { getTotalLineCountFromHunks } from '../utils/getTotalLineCountFromHunks' ;
5460import {
5561 createGutterGap ,
@@ -354,6 +360,23 @@ export class DiffHunksRenderer<
354360 : this . additionDecorationsByLine [ lineNumber ] ;
355361 }
356362
363+ protected mergeLineDecoration (
364+ decoration : LineDecoration ,
365+ lineDecorations : NormalizedLineDecorations | undefined
366+ ) : LineDecoration {
367+ return {
368+ ...decoration ,
369+ gutterProperties : mergeHastProperties (
370+ decoration . gutterProperties ,
371+ getLineDecorationGutterProperties ( lineDecorations )
372+ ) ,
373+ contentProperties : mergeHastProperties (
374+ decoration . contentProperties ,
375+ getLineDecorationContentProperties ( lineDecorations )
376+ ) ,
377+ } ;
378+ }
379+
357380 protected createAnnotationElement ( span : AnnotationSpan ) : HASTElement {
358381 return createDefaultAnnotationElement ( span ) ;
359382 }
@@ -864,24 +887,35 @@ export class DiffHunksRenderer<
864887 additionLineIndex : additionLine ?. lineIndex ,
865888 deletionLineIndex : deletionLine ?. lineIndex ,
866889 } ) ;
890+ const unifiedLineDecoration = this . mergeLineDecoration (
891+ lineDecoration ,
892+ mergeNormalizedLineDecorations (
893+ deletionLine != null
894+ ? this . getLineDecorations ( 'deletions' , deletionLine . lineNumber )
895+ : undefined ,
896+ additionLine != null
897+ ? this . getLineDecorations ( 'additions' , additionLine . lineNumber )
898+ : undefined
899+ )
900+ ) ;
867901 pushGutterLineNumber (
868902 'unified' ,
869- lineDecoration . gutterLineType ,
903+ unifiedLineDecoration . gutterLineType ,
870904 additionLine != null
871905 ? additionLine . lineNumber
872906 : deletionLine . lineNumber ,
873907 `${ unifiedLineIndex } ,${ splitLineIndex } ` ,
874- lineDecoration . gutterProperties
908+ unifiedLineDecoration . gutterProperties
875909 ) ;
876910 if ( additionLineContent != null ) {
877911 additionLineContent = withContentProperties (
878912 additionLineContent ,
879- lineDecoration . contentProperties
913+ unifiedLineDecoration . contentProperties
880914 ) ;
881915 } else if ( deletionLineContent != null ) {
882916 deletionLineContent = withContentProperties (
883917 deletionLineContent ,
884- lineDecoration . contentProperties
918+ unifiedLineDecoration . contentProperties
885919 ) ;
886920 }
887921 pushLineWithAnnotation ( {
@@ -932,6 +966,18 @@ export class DiffHunksRenderer<
932966 type,
933967 lineIndex : additionLine ?. lineIndex ,
934968 } ) ;
969+ const decoratedDeletionLine = this . mergeLineDecoration (
970+ deletionLineDecoration ,
971+ deletionLine != null
972+ ? this . getLineDecorations ( 'deletions' , deletionLine . lineNumber )
973+ : undefined
974+ ) ;
975+ const decoratedAdditionLine = this . mergeLineDecoration (
976+ additionLineDecoration ,
977+ additionLine != null
978+ ? this . getLineDecorations ( 'additions' , additionLine . lineNumber )
979+ : undefined
980+ ) ;
935981
936982 if ( deletionLineContent == null && additionLineContent == null ) {
937983 const errorMessage =
@@ -978,14 +1024,14 @@ export class DiffHunksRenderer<
9781024 if ( deletionLine != null ) {
9791025 const deletionLineDecorated = withContentProperties (
9801026 deletionLineContent ,
981- deletionLineDecoration . contentProperties
1027+ decoratedDeletionLine . contentProperties
9821028 ) ;
9831029 pushGutterLineNumber (
9841030 'deletions' ,
985- deletionLineDecoration . gutterLineType ,
1031+ decoratedDeletionLine . gutterLineType ,
9861032 deletionLine . lineNumber ,
9871033 `${ deletionLine . unifiedLineIndex } ,${ splitLineIndex } ` ,
988- deletionLineDecoration . gutterProperties
1034+ decoratedDeletionLine . gutterProperties
9891035 ) ;
9901036 if ( deletionLineDecorated != null ) {
9911037 deletionLineContent = deletionLineDecorated ;
@@ -994,14 +1040,14 @@ export class DiffHunksRenderer<
9941040 if ( additionLine != null ) {
9951041 const additionLineDecorated = withContentProperties (
9961042 additionLineContent ,
997- additionLineDecoration . contentProperties
1043+ decoratedAdditionLine . contentProperties
9981044 ) ;
9991045 pushGutterLineNumber (
10001046 'additions' ,
1001- additionLineDecoration . gutterLineType ,
1047+ decoratedAdditionLine . gutterLineType ,
10021048 additionLine . lineNumber ,
10031049 `${ additionLine . unifiedLineIndex } ,${ splitLineIndex } ` ,
1004- additionLineDecoration . gutterProperties
1050+ decoratedAdditionLine . gutterProperties
10051051 ) ;
10061052 if ( additionLineDecorated != null ) {
10071053 additionLineContent = additionLineDecorated ;
@@ -1588,8 +1634,7 @@ function withContentProperties(
15881634 return {
15891635 ...lineNode ,
15901636 properties : {
1591- ...lineNode . properties ,
1592- ...contentProperties ,
1637+ ...( mergeHastProperties ( lineNode . properties , contentProperties ) ?? { } ) ,
15931638 } ,
15941639 } ;
15951640}
0 commit comments