Skip to content

Commit 30a45a6

Browse files
authored
Diff compression (#1810)
* Add diff compression * Fix existing 'React has detected a change in the order of Hooks called by DiffCell.' issue * Allow compressed runs to be expanded * smol tweak to button hover * don't forget about the 3rd column * remove debugging log * Move early return *after* hooks to ensure consistency * Remove usage of useEffect * nits * pull CompressToggleButton into its own function * yarn lint
1 parent 65c3299 commit 30a45a6

File tree

7 files changed

+278
-31
lines changed

7 files changed

+278
-31
lines changed

frontend/src/app/(navfooter)/settings/SliderField.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ export default function SliderField({
5858
</div>
5959

6060
<div className="inline-flex w-5/6 items-center gap-2 text-gray-10 text-xs">
61-
{min}
62-
{unit}
61+
<span className="w-1/6 text-right">
62+
{min}
63+
{unit}
64+
</span>
6365
<input
6466
id={id}
6567
type="range"
@@ -71,10 +73,12 @@ export default function SliderField({
7173
onChange(clamp(+evt.target.value, min, max))
7274
}
7375
disabled={disabled}
74-
className="w-full focus:ring"
76+
className="w-4/6 focus:ring"
7577
/>
76-
{max}
77-
{unit}
78+
<span className="w-1/6">
79+
{max}
80+
{unit}
81+
</span>
7882
</div>
7983
</div>
8084

frontend/src/app/(navfooter)/settings/appearance/AppearanceSettings.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export default function AppearanceSettings() {
2020
const [codeColorScheme, setCodeColorScheme] = settings.useCodeColorScheme();
2121
const [diffCellBackground, setDiffCellBackground] =
2222
settings.diffCellBackgroundEnabled();
23+
const [diffCompressionContext, setDiffCompressionContext] =
24+
settings.diffCompressionContext();
2325

2426
return (
2527
<>
@@ -77,6 +79,17 @@ export default function AppearanceSettings() {
7779
checked={diffCellBackground}
7880
onChange={setDiffCellBackground}
7981
/>
82+
<div className="my-6 md:mb-0 md:w-full">
83+
<SliderField
84+
label="Diff compression context"
85+
min={0}
86+
max={8}
87+
step={1}
88+
unit=" row(s)"
89+
value={diffCompressionContext}
90+
onChange={setDiffCompressionContext}
91+
/>
92+
</div>
8093
</div>
8194

8295
<div className="mb-6 max-w-xl">

frontend/src/components/Diff/CompilationPanel.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export default function CompilationPanel({
5353
const problemState = getProblemState(compilation);
5454
const [threeWayDiffBase] = useThreeWayDiffBase();
5555
const [threeWayDiffEnabled, setThreeWayDiffEnabled] = useState(false);
56+
const [compressionEnabled, setCompressionEnabled] = useState(false);
5657
const prevCompilation = usedCompilationRef.current;
5758

5859
// Only update the diff if it's never been set or if the compilation succeeded
@@ -118,6 +119,8 @@ export default function CompilationPanel({
118119
}
119120
threeWayDiffEnabled={threeWayDiffEnabled}
120121
setThreeWayDiffEnabled={setThreeWayDiffEnabled}
122+
compressionEnabled={compressionEnabled}
123+
setCompressionEnabled={setCompressionEnabled}
121124
threeWayDiffBase={threeWayDiffBase}
122125
selectedSourceLine={selectedSourceLine}
123126
/>

frontend/src/components/Diff/Diff.module.scss

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@
5858
color: var(--g1500);
5959
}
6060

61+
.compressionToggle {
62+
position: relative;
63+
padding: 4px 4px;
64+
cursor: pointer;
65+
66+
&:hover {
67+
border-radius: 4px;
68+
color: var(--g1300);
69+
background: var(--g400);
70+
}
71+
}
72+
6173
// Columns
6274
.headers,
6375
.row {
@@ -116,6 +128,14 @@
116128
}
117129
}
118130

131+
.row.collapsed {
132+
cursor: pointer;
133+
}
134+
135+
.row.collapsed > .cell {
136+
cursor: pointer;
137+
}
138+
119139
.cell span.lineNumber {
120140
display: inline-block;
121141

@@ -145,19 +165,23 @@
145165
.diff_change { color: #6d6dff; }
146166
.diff_add { color: #45bd00; }
147167
.diff_remove { color: #c82829; }
168+
.diff_skip { color: #e6c700; }
148169

149170
.diff_change_row { background-color: rgba(106, 106, 255, 0.10); }
150171
.diff_add_row { background-color: rgba(69, 189, 0, 0.10); }
151172
.diff_remove_row { background-color: rgba(200, 40, 41, 0.10); }
173+
.diff_skip_row { background-color: rgba(230, 199, 0, 0.10); }
152174

153175
:global(html:not(.dark)) {
154176
.diff_change { color: #3a3aff; }
155177
.diff_add { color: #2a8000; }
156178
.diff_remove { color: #a31212; }
179+
.diff_skip { color: #b38f00; }
157180

158181
.diff_change_row { background-color: #f4f4ff; }
159182
.diff_add_row { background-color: #f4fff4; }
160183
.diff_remove_row { background-color: #fff4f4; }
184+
.diff_skip_row { background-color: #fffbea; }
161185
}
162186

163187
.source_function {

0 commit comments

Comments
 (0)