MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / renderColorDiff

Function renderColorDiff

source code/components/StructuredDiff.tsx:52–96  ·  view source on GitHub ↗
(patch: StructuredPatchHunk, firstLine: string | null, filePath: string, fileContent: string | null, theme: string, width: number, dim: boolean, splitGutter: boolean)

Source from the content-addressed store, hash-verified

50 return maxLineNumber.toString().length + 3; // marker + 2 padding spaces
51}
52function renderColorDiff(patch: StructuredPatchHunk, firstLine: string | null, filePath: string, fileContent: string | null, theme: string, width: number, dim: boolean, splitGutter: boolean): CachedRender | null {
53 const ColorDiff = expectColorDiff();
54 if (!ColorDiff) return null;
55
56 // Defensive: if the gutter would eat the whole render width (narrow
57 // terminal), skip the split. Rust already wraps to `width` so the
58 // single-column output stays correct; we just lose noSelect. Without
59 // this, sliceAnsi(line, gutterWidth) would return empty content and
60 // RawAnsi(width<=0) is untested.
61 const rawGutterWidth = splitGutter ? computeGutterWidth(patch) : 0;
62 const gutterWidth = rawGutterWidth > 0 && rawGutterWidth < width ? rawGutterWidth : 0;
63 const key = `${theme}|${width}|${dim ? 1 : 0}|${gutterWidth}|${firstLine ?? ''}|${filePath}`;
64 let perHunk = RENDER_CACHE.get(patch);
65 const hit = perHunk?.get(key);
66 if (hit) return hit;
67 const lines = new ColorDiff(patch, firstLine, filePath, fileContent).render(theme, width, dim);
68 if (lines === null) return null;
69
70 // Pre-split the gutter column once (cold-cache). sliceAnsi preserves
71 // styles across the cut; the Rust module already pads the gutter to
72 // gutterWidth so the narrow RawAnsi column's width matches its cells.
73 let gutters: string[] | null = null;
74 let contents: string[] | null = null;
75 if (gutterWidth > 0) {
76 gutters = lines.map(l => sliceAnsi(l, 0, gutterWidth));
77 contents = lines.map(l => sliceAnsi(l, gutterWidth));
78 }
79 const entry: CachedRender = {
80 lines,
81 gutterWidth,
82 gutters,
83 contents
84 };
85 if (!perHunk) {
86 perHunk = new Map();
87 RENDER_CACHE.set(patch, perHunk);
88 }
89 // Cap the inner map: width is part of the key, so terminal resize while a
90 // diff is visible accumulates a full render copy per distinct width. Four
91 // variants (two widths × dim on/off) covers the steady state; beyond that
92 // the user is actively resizing and old widths are stale.
93 if (perHunk.size >= 4) perHunk.clear();
94 perHunk.set(key, entry);
95 return entry;
96}
97export const StructuredDiff = memo(function StructuredDiff(t0) {
98 const $ = _c(26);
99 const {

Callers 1

StructuredDiff.tsxFile · 0.85

Calls 7

expectColorDiffFunction · 0.85
computeGutterWidthFunction · 0.85
sliceAnsiFunction · 0.85
setMethod · 0.80
getMethod · 0.45
renderMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected