Skip to content

Commit 3c25457

Browse files
committed
🤖 Fix diff text wrapping in code review
Long lines in code review diffs now wrap to fit the visible boundaries instead of extending horizontally with scrollbars. Changes: - DiffLine: white-space: pre → pre-wrap + word-break: break-all - DiffContainer: overflow-x: auto → hidden, grid: minmax(...) → 1fr - Updated comments to reflect wrapping behavior
1 parent dee39f5 commit 3c25457

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

‎src/components/shared/DiffRenderer.tsx‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,15 @@ const getContrastColor = (type: DiffLineType) => {
2626
};
2727

2828
/**
29-
* Wrapper for diff lines - works with CSS Grid parent to ensure uniform widths
29+
* Wrapper for diff lines - provides consistent backgrounds for wrapped content
3030
*
31-
* Problem: Lines of varying length created jagged backgrounds during horizontal scroll
32-
* because each wrapper was only as wide as its content.
33-
*
34-
* Solution: Parent container uses CSS Grid, which automatically makes all grid items
35-
* (these wrappers) the same width as the widest item. This ensures backgrounds span
36-
* the full scrollable area without creating infinite scroll.
37-
*
38-
* Key insight: width: 100% makes each wrapper span the full grid column width,
39-
* which CSS Grid automatically sets to the widest line's content.
31+
* Lines wrap to fit visible boundaries (no horizontal scroll). Background colors
32+
* span the full width of the container to maintain visual continuity even when
33+
* content wraps across multiple lines.
4034
*/
4135
export const DiffLineWrapper = styled.div<{ type: DiffLineType }>`
4236
display: block;
43-
width: 100%; /* Span full grid column (width of longest line) */
37+
width: 100%;
4438
4539
background: ${({ type }) => {
4640
switch (type) {
@@ -56,7 +50,8 @@ export const DiffLineWrapper = styled.div<{ type: DiffLineType }>`
5650

5751
export const DiffLine = styled.div<{ type: DiffLineType }>`
5852
font-family: var(--font-monospace);
59-
white-space: pre;
53+
white-space: pre-wrap;
54+
word-break: break-all;
6055
display: flex;
6156
padding: ${({ type }) => (type === "header" ? "4px 8px" : "0 8px")};
6257
color: ${({ type }) => {
@@ -126,11 +121,11 @@ export const DiffContainer = styled.div<{ fontSize?: string; maxHeight?: string
126121
line-height: 1.4;
127122
max-height: ${({ maxHeight }) => maxHeight ?? "400px"};
128123
overflow-y: auto;
129-
overflow-x: auto;
124+
overflow-x: hidden;
130125
131-
/* CSS Grid ensures all lines span the same width (width of longest line) */
126+
/* CSS Grid with content wrapping to fit visible boundaries */
132127
display: grid;
133-
grid-template-columns: minmax(min-content, 1fr);
128+
grid-template-columns: 1fr;
134129
135130
/* Ensure all child elements inherit font size from container */
136131
* {

0 commit comments

Comments
 (0)