@@ -5,22 +5,10 @@ import { Box, Text } from "ink";
55import * as React from "react" ;
66
77import { buildAnsiStringWithLineBreaks , buildStyledBlock , type CharStyle } from "./ansiString" ;
8- import {
9- diffAddContent ,
10- diffAddContentHighlight ,
11- diffDelContent ,
12- diffDelContentHighlight ,
13- diffExpandContent ,
14- diffPlainContent ,
15- noBGDiffAddContent ,
16- noBGDiffAddContentHighlight ,
17- noBGDiffDelContent ,
18- noBGDiffDelContentHighlight ,
19- GitHubDark ,
20- GitHubLight ,
21- } from "./color" ;
8+ import { GitHubDark , GitHubLight } from "./color" ;
229import { useDiffViewContext } from "./DiffViewContext" ;
2310
11+ import type { ResolvedDiffViewColorTheme } from "./color" ;
2412import type { DiffFile , DiffLine , File } from "@git-diff-view/core" ;
2513
2614// Helper to get tab width value
@@ -115,6 +103,7 @@ const DiffString = React.memo(
115103 diffLine,
116104 operator,
117105 noBG,
106+ themeColors,
118107 } : {
119108 bg ?: string ;
120109 width : number ;
@@ -125,6 +114,7 @@ const DiffString = React.memo(
125114 operator ?: "add" | "del" ;
126115 plainLine ?: File [ "plainFile" ] [ number ] ;
127116 noBG ?: boolean ;
117+ themeColors : ResolvedDiffViewColorTheme ;
128118 } ) => {
129119 const changes = diffLine ?. changes ;
130120
@@ -145,8 +135,8 @@ const DiffString = React.memo(
145135 const str2 = rawLine . slice ( range . location , range . location + range . length ) ;
146136 const str3 = rawLine . slice ( range . location + range . length ) ;
147137
148- const addHighlight = noBG ? noBGDiffAddContentHighlight : diffAddContentHighlight ;
149- const delHighlight = noBG ? noBGDiffDelContentHighlight : diffDelContentHighlight ;
138+ const addHighlight = noBG ? themeColors . noBGAddContentHighlight : themeColors . addContentHighlight ;
139+ const delHighlight = noBG ? themeColors . noBGDelContentHighlight : themeColors . delContentHighlight ;
150140 const highlightBG =
151141 operator === "add"
152142 ? theme === "light"
@@ -176,7 +166,7 @@ const DiffString = React.memo(
176166
177167 // Use width - 2 because the operator column takes 1 character and end padding takes 1 character
178168 return buildAnsiStringWithLineBreaks ( chars , width - 2 ) ;
179- } , [ bg , width , theme , rawLine , changes , operator , enableTabSpace , tabWidth , noBG ] ) ;
169+ } , [ bg , width , theme , rawLine , changes , operator , enableTabSpace , tabWidth , noBG , themeColors ] ) ;
180170
181171 return (
182172 < Box width = { width - 2 } backgroundColor = { bg } >
@@ -246,6 +236,7 @@ const DiffSyntax = React.memo(
246236 operator,
247237 syntaxLine,
248238 noBG,
239+ themeColors,
249240 } : {
250241 bg ?: string ;
251242 width : number ;
@@ -256,6 +247,7 @@ const DiffSyntax = React.memo(
256247 syntaxLine ?: File [ "syntaxFile" ] [ number ] ;
257248 operator ?: "add" | "del" ;
258249 noBG ?: boolean ;
250+ themeColors : ResolvedDiffViewColorTheme ;
259251 } ) => {
260252 const { useDiffContext } = useDiffViewContext ( ) ;
261253
@@ -273,8 +265,8 @@ const DiffSyntax = React.memo(
273265 const chars : Array < { char : string ; style ?: CharStyle } > = [ ] ;
274266 const baseStyle : CharStyle = { backgroundColor : bg } ;
275267
276- const addHighlight = noBG ? noBGDiffAddContentHighlight : diffAddContentHighlight ;
277- const delHighlight = noBG ? noBGDiffDelContentHighlight : diffDelContentHighlight ;
268+ const addHighlight = noBG ? themeColors . noBGAddContentHighlight : themeColors . addContentHighlight ;
269+ const delHighlight = noBG ? themeColors . noBGDelContentHighlight : themeColors . delContentHighlight ;
278270 const highlightBG =
279271 operator === "add"
280272 ? theme === "light"
@@ -355,7 +347,7 @@ const DiffSyntax = React.memo(
355347
356348 // Use width - 2 because the operator column takes 1 character and end padding takes 1 character
357349 return buildAnsiStringWithLineBreaks ( chars , width - 2 ) ;
358- } , [ bg , width , theme , diffLine , operator , syntaxLine , enableTabSpace , tabWidth , noBG ] ) ;
350+ } , [ bg , width , theme , diffLine , operator , syntaxLine , enableTabSpace , tabWidth , noBG , themeColors ] ) ;
359351
360352 // Fallback to DiffString if no syntax line
361353 if ( ! syntaxLine ) {
@@ -369,6 +361,7 @@ const DiffSyntax = React.memo(
369361 diffLine = { diffLine }
370362 operator = { operator }
371363 noBG = { noBG }
364+ themeColors = { themeColors }
372365 />
373366 ) ;
374367 }
@@ -448,6 +441,7 @@ export const DiffContent = React.memo(
448441 syntaxLine,
449442 enableHighlight,
450443 noBG,
444+ themeColors,
451445 } : {
452446 width : number ;
453447 height : number ;
@@ -459,6 +453,7 @@ export const DiffContent = React.memo(
459453 diffFile : DiffFile ;
460454 enableHighlight : boolean ;
461455 noBG ?: boolean ;
456+ themeColors : ResolvedDiffViewColorTheme ;
462457 } ) => {
463458 const { useDiffContext } = useDiffViewContext ( ) ;
464459
@@ -469,19 +464,19 @@ export const DiffContent = React.memo(
469464 const isMaxLineLengthToIgnoreSyntax = syntaxLine && syntaxLine ?. nodeList ?. length > 150 ;
470465
471466 const bg = React . useMemo ( ( ) => {
472- const addColors = noBG ? noBGDiffAddContent : diffAddContent ;
473- const delColors = noBG ? noBGDiffDelContent : diffDelContent ;
467+ const addColors = noBG ? themeColors . noBGAddContent : themeColors . addContent ;
468+ const delColors = noBG ? themeColors . noBGDelContent : themeColors . delContent ;
474469 if ( isAdded ) return theme === "light" ? addColors . light : addColors . dark ;
475470 if ( isDelete ) return theme === "light" ? delColors . light : delColors . dark ;
476471 if ( noBG ) return undefined ;
477472 return theme === "light"
478473 ? diffLine
479- ? diffPlainContent . light
480- : diffExpandContent . light
474+ ? themeColors . plainContent . light
475+ : themeColors . expandContent . light
481476 : diffLine
482- ? diffPlainContent . dark
483- : diffExpandContent . dark ;
484- } , [ theme , diffLine , isAdded , isDelete , noBG ] ) ;
477+ ? themeColors . plainContent . dark
478+ : themeColors . expandContent . dark ;
479+ } , [ theme , diffLine , isAdded , isDelete , noBG , themeColors ] ) ;
485480
486481 const operatorChar = isAdded ? "+" : isDelete ? "-" : " " ;
487482
@@ -503,6 +498,7 @@ export const DiffContent = React.memo(
503498 diffLine = { diffLine }
504499 syntaxLine = { syntaxLine }
505500 noBG = { noBG }
501+ themeColors = { themeColors }
506502 />
507503 ) : (
508504 < DiffString
@@ -515,6 +511,7 @@ export const DiffContent = React.memo(
515511 diffLine = { diffLine }
516512 plainLine = { plainLine }
517513 noBG = { noBG }
514+ themeColors = { themeColors }
518515 />
519516 ) }
520517 < DiffPadding height = { height } backgroundColor = { bg } />
0 commit comments