Skip to content

Commit 2c3e68a

Browse files
authored
🤖 fix: align diff styling with app theme (#1124)
Tweaks diff rendering to better match mux's overall UI: theme-based diff colors, subtle per-line accents, and more consistent code container styling. _Generated with `mux`_
1 parent f4d0c54 commit 2c3e68a

File tree

3 files changed

+78
-53
lines changed

3 files changed

+78
-53
lines changed

src/browser/components/RightSidebar/CodeReview/HunkViewer.tsx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -248,25 +248,25 @@ export const HunkViewer = React.memo<HunkViewerProps>(
248248
Renamed from <code>{hunk.oldPath}</code>
249249
</div>
250250
) : isExpanded ? (
251-
<div className="font-monospace bg-code-bg grid grid-cols-[minmax(min-content,1fr)] overflow-x-auto px-2 py-1.5 text-[11px] leading-[1.4]">
252-
<SelectableDiffRenderer
253-
content={hunk.content}
254-
filePath={hunk.filePath}
255-
oldStart={hunk.oldStart}
256-
newStart={hunk.newStart}
257-
maxHeight="none"
258-
onReviewNote={onReviewNote}
259-
onLineClick={() => {
260-
// Create synthetic event with data-hunk-id for parent handler
261-
const syntheticEvent = {
262-
currentTarget: { dataset: { hunkId } },
263-
} as unknown as React.MouseEvent<HTMLElement>;
264-
onClick?.(syntheticEvent);
265-
}}
266-
searchConfig={searchConfig}
267-
enableHighlighting={isVisible}
268-
/>
269-
</div>
251+
<SelectableDiffRenderer
252+
content={hunk.content}
253+
filePath={hunk.filePath}
254+
oldStart={hunk.oldStart}
255+
newStart={hunk.newStart}
256+
fontSize="11px"
257+
maxHeight="none"
258+
className="rounded-none border-0"
259+
onReviewNote={onReviewNote}
260+
onLineClick={() => {
261+
// Create synthetic event with data-hunk-id for parent handler
262+
const syntheticEvent = {
263+
currentTarget: { dataset: { hunkId } },
264+
} as unknown as React.MouseEvent<HTMLElement>;
265+
onClick?.(syntheticEvent);
266+
}}
267+
searchConfig={searchConfig}
268+
enableHighlighting={isVisible}
269+
/>
270270
) : (
271271
<div
272272
className="text-muted hover:text-foreground cursor-pointer px-3 py-2 text-center text-[11px] italic"

src/browser/components/shared/DiffRenderer.tsx

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,51 +23,64 @@ import type { ReviewNoteData } from "@/common/types/review";
2323
// Shared type for diff line types
2424
export type DiffLineType = "add" | "remove" | "context" | "header";
2525

26-
// Helper function for getting diff line background color
26+
// Helper function for getting diff line background color.
27+
// Keep backgrounds subtle so the diff reads like a code block, not a highlighter.
2728
const getDiffLineBackground = (type: DiffLineType): string => {
2829
switch (type) {
2930
case "add":
30-
return "rgba(46, 160, 67, 0.15)";
31+
return "color-mix(in srgb, var(--color-success), transparent 90%)";
3132
case "remove":
32-
return "rgba(248, 81, 73, 0.15)";
33+
return "color-mix(in srgb, var(--color-danger), transparent 90%)";
34+
case "header":
35+
return "color-mix(in srgb, var(--color-accent), transparent 92%)";
36+
case "context":
3337
default:
3438
return "transparent";
3539
}
3640
};
3741

38-
// Helper function for getting diff line text color
39-
const getDiffLineColor = (type: DiffLineType): string => {
42+
const getDiffLineBorderColor = (type: DiffLineType): string => {
4043
switch (type) {
4144
case "add":
42-
return "#4caf50";
45+
return "color-mix(in srgb, var(--color-success), transparent 35%)";
4346
case "remove":
44-
return "#f44336";
47+
return "color-mix(in srgb, var(--color-danger), transparent 35%)";
4548
case "header":
46-
return "#2196f3";
49+
return "color-mix(in srgb, var(--color-accent), transparent 45%)";
4750
case "context":
4851
default:
49-
return "var(--color-text)";
52+
return "transparent";
5053
}
5154
};
5255

53-
// Helper function for getting line content color
56+
// Helper function for getting line content color.
57+
// Only headers/context are tinted; actual code stays the normal foreground color.
5458
const getLineContentColor = (type: DiffLineType): string => {
5559
switch (type) {
5660
case "header":
57-
return "#2196f3";
61+
return "var(--color-accent-light)";
5862
case "context":
5963
return "var(--color-text-secondary)";
6064
case "add":
6165
case "remove":
66+
default:
6267
return "var(--color-text)";
6368
}
6469
};
6570

66-
// Helper function for computing contrast color for add/remove indicators
71+
// Used for the +/- marker and line numbers.
6772
const getContrastColor = (type: DiffLineType): string => {
68-
return type === "add" || type === "remove"
69-
? "color-mix(in srgb, var(--color-text-secondary), white 50%)"
70-
: "var(--color-text-secondary)";
73+
switch (type) {
74+
case "add":
75+
return "var(--color-success-light)";
76+
case "remove":
77+
return "var(--color-danger-soft)";
78+
case "header":
79+
return "var(--color-accent-light)";
80+
case "context":
81+
default:
82+
return "var(--color-text-secondary)";
83+
}
7184
};
7285

7386
/**
@@ -115,7 +128,12 @@ export const DiffContainer: React.FC<
115128
const showOverflowControls = clampContent && isOverflowing;
116129

117130
return (
118-
<div className={cn("relative m-0 rounded bg-code-bg py-1.5 [&_*]:text-[inherit]", className)}>
131+
<div
132+
className={cn(
133+
"relative m-0 rounded-sm border border-border-light bg-code-bg py-1.5 [&_*]:text-[inherit]",
134+
className
135+
)}
136+
>
119137
<div
120138
ref={contentRef}
121139
className={cn(
@@ -271,12 +289,15 @@ export const DiffRenderer: React.FC<DiffRendererProps> = ({
271289
return (
272290
<div
273291
key={line.originalIndex}
274-
className="block w-full"
275-
style={{ background: getDiffLineBackground(chunk.type) }}
292+
className="block w-full border-l-2 border-transparent"
293+
style={{
294+
background: getDiffLineBackground(chunk.type),
295+
borderLeftColor: getDiffLineBorderColor(chunk.type),
296+
}}
276297
>
277298
<div
278-
className="flex px-2 font-mono whitespace-pre"
279-
style={{ color: getDiffLineColor(chunk.type) }}
299+
className="font-monospace flex px-2 whitespace-pre"
300+
style={{ color: "var(--color-text)" }}
280301
>
281302
<span
282303
className="inline-block w-1 shrink-0 text-center"
@@ -451,6 +472,7 @@ export const SelectableDiffRenderer = React.memo<SelectableDiffRendererProps>(
451472
filePath,
452473
fontSize,
453474
maxHeight,
475+
className,
454476
onReviewNote,
455477
onLineClick,
456478
searchConfig,
@@ -556,7 +578,7 @@ export const SelectableDiffRenderer = React.memo<SelectableDiffRendererProps>(
556578
// Show loading state while highlighting
557579
if (!highlightedChunks || highlightedLineData.length === 0) {
558580
return (
559-
<DiffContainer fontSize={fontSize} maxHeight={maxHeight}>
581+
<DiffContainer fontSize={fontSize} maxHeight={maxHeight} className={className}>
560582
<div style={{ opacity: 0.5, padding: "8px" }}>Processing...</div>
561583
</DiffContainer>
562584
);
@@ -566,7 +588,7 @@ export const SelectableDiffRenderer = React.memo<SelectableDiffRendererProps>(
566588
const lines = content.split("\n").filter((line) => line.length > 0);
567589

568590
return (
569-
<DiffContainer fontSize={fontSize} maxHeight={maxHeight}>
591+
<DiffContainer fontSize={fontSize} maxHeight={maxHeight} className={className}>
570592
{highlightedLineData.map((lineInfo, displayIndex) => {
571593
const isSelected = isLineSelected(displayIndex);
572594
const indicator = lineInfo.type === "add" ? "+" : lineInfo.type === "remove" ? "-" : " ";
@@ -576,12 +598,13 @@ export const SelectableDiffRenderer = React.memo<SelectableDiffRendererProps>(
576598
<div
577599
className={cn(
578600
SELECTABLE_DIFF_LINE_CLASS,
579-
"block w-full relative cursor-text group"
601+
"block w-full relative cursor-text group border-l-2 border-transparent"
580602
)}
581603
style={{
582604
background: isSelected
583605
? "hsl(from var(--color-review-accent) h s l / 0.2)"
584606
: getDiffLineBackground(lineInfo.type),
607+
borderLeftColor: getDiffLineBorderColor(lineInfo.type),
585608
}}
586609
>
587610
<span className="absolute top-1/2 left-1 z-[1] -translate-y-1/2">
@@ -618,8 +641,8 @@ export const SelectableDiffRenderer = React.memo<SelectableDiffRendererProps>(
618641
</Tooltip>
619642
</span>
620643
<div
621-
className="flex px-2 font-mono whitespace-pre"
622-
style={{ color: getDiffLineColor(lineInfo.type) }}
644+
className="font-monospace flex px-2 whitespace-pre"
645+
style={{ color: "var(--color-text)" }}
623646
>
624647
<span
625648
className="inline-block w-1 shrink-0 text-center"

src/browser/components/tools/FileEditToolCall.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,17 @@ export const FileEditToolCall: React.FC<FileEditToolCallProps> = ({
160160
</DetailSection>
161161
)}
162162

163-
{result.success && result.diff && (
164-
<DiffContainer>
165-
{showRaw ? (
166-
<pre className="m-0 break-words whitespace-pre-wrap">{result.diff}</pre>
167-
) : (
168-
renderDiff(result.diff, filePath, onReviewNote)
169-
)}
170-
</DiffContainer>
171-
)}
163+
{result.success &&
164+
result.diff &&
165+
(showRaw ? (
166+
<DiffContainer>
167+
<pre className="font-monospace m-0 text-[11px] leading-[1.4] break-words whitespace-pre-wrap">
168+
{result.diff}
169+
</pre>
170+
</DiffContainer>
171+
) : (
172+
renderDiff(result.diff, filePath, onReviewNote)
173+
))}
172174
</>
173175
)}
174176

0 commit comments

Comments
 (0)