@@ -283,11 +283,14 @@ export class DiffRenderable extends Renderable {
283283 }
284284 }
285285
286+ // If we have word highlights, don't show the full line background - only the word highlights
287+ const hasWordHighlights = leftHighlights . length > 0 || rightHighlights . length > 0
288+
286289 if ( remove ) {
287290 leftLines . push ( {
288291 content : remove . content ,
289292 lineNum : remove . lineNum ,
290- color : this . _removedBg ,
293+ color : hasWordHighlights ? this . _contextBg : this . _removedBg ,
291294 sign : {
292295 after : " -" ,
293296 afterColor : this . _removedSignColor ,
@@ -307,7 +310,7 @@ export class DiffRenderable extends Renderable {
307310 rightLines . push ( {
308311 content : add . content ,
309312 lineNum : add . lineNum ,
310- color : this . _addedBg ,
313+ color : hasWordHighlights ? this . _contextBg : this . _addedBg ,
311314 sign : {
312315 after : " +" ,
313316 afterColor : this . _addedSignColor ,
@@ -704,29 +707,37 @@ export class DiffRenderable extends Renderable {
704707 for ( const line of processedBlock . leftLines ) {
705708 if ( line . type === "empty" ) continue
706709 contentLines . push ( line . content )
710+ // If we have word highlights, use context background instead of removed background
711+ const hasWordHighlights = line . inlineHighlights && line . inlineHighlights . length > 0
707712 lineColors . set ( lineIndex , {
708713 gutter : this . _removedLineNumberBg ,
709- content : this . _removedContentBg ?? this . _removedBg ,
714+ content : hasWordHighlights
715+ ? ( this . _contextContentBg ?? this . _contextBg )
716+ : ( this . _removedContentBg ?? this . _removedBg ) ,
710717 } )
711718 lineSigns . set ( lineIndex , { after : " -" , afterColor : this . _removedSignColor } )
712719 if ( line . lineNum !== undefined ) lineNumbers . set ( lineIndex , line . lineNum )
713- if ( line . inlineHighlights ?. length ) {
714- inlineHighlights . set ( lineIndex , this . toLineHighlights ( line . inlineHighlights , this . _removedWordBg ) )
720+ if ( hasWordHighlights ) {
721+ inlineHighlights . set ( lineIndex , this . toLineHighlights ( line . inlineHighlights ! , this . _removedWordBg ) )
715722 }
716723 lineIndex ++
717724 }
718725
719726 for ( const line of processedBlock . rightLines ) {
720727 if ( line . type === "empty" ) continue
721728 contentLines . push ( line . content )
729+ // If we have word highlights, use context background instead of added background
730+ const hasWordHighlights = line . inlineHighlights && line . inlineHighlights . length > 0
722731 lineColors . set ( lineIndex , {
723732 gutter : this . _addedLineNumberBg ,
724- content : this . _addedContentBg ?? this . _addedBg ,
733+ content : hasWordHighlights
734+ ? ( this . _contextContentBg ?? this . _contextBg )
735+ : ( this . _addedContentBg ?? this . _addedBg ) ,
725736 } )
726737 lineSigns . set ( lineIndex , { after : " +" , afterColor : this . _addedSignColor } )
727738 if ( line . lineNum !== undefined ) lineNumbers . set ( lineIndex , line . lineNum )
728- if ( line . inlineHighlights ?. length ) {
729- inlineHighlights . set ( lineIndex , this . toLineHighlights ( line . inlineHighlights , this . _addedWordBg ) )
739+ if ( hasWordHighlights ) {
740+ inlineHighlights . set ( lineIndex , this . toLineHighlights ( line . inlineHighlights ! , this . _addedWordBg ) )
730741 }
731742 lineIndex ++
732743 }
@@ -980,11 +991,15 @@ export class DiffRenderable extends Renderable {
980991 if ( line . hideLineNumber ) {
981992 leftHideLineNumbers . add ( index )
982993 }
994+ const hasWordHighlights = line . inlineHighlights && line . inlineHighlights . length > 0
983995 if ( line . type === "remove" ) {
984996 const config : LineColorConfig = {
985997 gutter : this . _removedLineNumberBg ,
986998 }
987- if ( this . _removedContentBg ) {
999+ // If we have word highlights, use context background instead of removed background
1000+ if ( hasWordHighlights ) {
1001+ config . content = this . _contextContentBg ?? this . _contextBg
1002+ } else if ( this . _removedContentBg ) {
9881003 config . content = this . _removedContentBg
9891004 } else {
9901005 config . content = this . _removedBg
@@ -1004,8 +1019,8 @@ export class DiffRenderable extends Renderable {
10041019 if ( line . sign ) {
10051020 leftLineSigns . set ( index , line . sign )
10061021 }
1007- if ( line . inlineHighlights ?. length ) {
1008- leftInlineHighlights . set ( index , this . toLineHighlights ( line . inlineHighlights , this . _removedWordBg ) )
1022+ if ( hasWordHighlights ) {
1023+ leftInlineHighlights . set ( index , this . toLineHighlights ( line . inlineHighlights ! , this . _removedWordBg ) )
10091024 }
10101025 } )
10111026
@@ -1016,11 +1031,15 @@ export class DiffRenderable extends Renderable {
10161031 if ( line . hideLineNumber ) {
10171032 rightHideLineNumbers . add ( index )
10181033 }
1034+ const hasWordHighlights = line . inlineHighlights && line . inlineHighlights . length > 0
10191035 if ( line . type === "add" ) {
10201036 const config : LineColorConfig = {
10211037 gutter : this . _addedLineNumberBg ,
10221038 }
1023- if ( this . _addedContentBg ) {
1039+ // If we have word highlights, use context background instead of added background
1040+ if ( hasWordHighlights ) {
1041+ config . content = this . _contextContentBg ?? this . _contextBg
1042+ } else if ( this . _addedContentBg ) {
10241043 config . content = this . _addedContentBg
10251044 } else {
10261045 config . content = this . _addedBg
@@ -1040,8 +1059,8 @@ export class DiffRenderable extends Renderable {
10401059 if ( line . sign ) {
10411060 rightLineSigns . set ( index , line . sign )
10421061 }
1043- if ( line . inlineHighlights ?. length ) {
1044- rightInlineHighlights . set ( index , this . toLineHighlights ( line . inlineHighlights , this . _addedWordBg ) )
1062+ if ( hasWordHighlights ) {
1063+ rightInlineHighlights . set ( index , this . toLineHighlights ( line . inlineHighlights ! , this . _addedWordBg ) )
10451064 }
10461065 } )
10471066
0 commit comments