Skip to content

Commit 473f3fa

Browse files
committed
pull CompressToggleButton into its own function
1 parent 2c7e17d commit 473f3fa

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

frontend/src/components/Diff/Diff.tsx

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint css-modules/no-unused-class: off */
2-
32
import {
43
createContext,
54
type CSSProperties,
@@ -147,7 +146,7 @@ function DiffBody({
147146
}) => (
148147
<FixedSizeList
149148
className={styles.body}
150-
itemCount={flattened.length}
149+
itemCount={itemData.rows.length}
151150
itemData={itemData}
152151
itemSize={(fontSize ?? 12) * 1.33}
153152
overscanCount={40}
@@ -187,6 +186,30 @@ function ThreeWayToggleButton({
187186
);
188187
}
189188

189+
function CompressToggleButton({
190+
enabled,
191+
setEnabled,
192+
}: {
193+
enabled: boolean;
194+
setEnabled: (enabled: boolean) => void;
195+
}) {
196+
return (
197+
<button
198+
className={styles.compressionToggle}
199+
onClick={() => {
200+
setEnabled(!enabled);
201+
}}
202+
title={
203+
enabled
204+
? "Do not compress streaks of matching lines"
205+
: "Compress streaks of matching lines"
206+
}
207+
>
208+
{enabled ? <FoldIcon size={24} /> : <UnfoldIcon size={24} />}
209+
</button>
210+
);
211+
}
212+
190213
export function scrollToLineNumber(
191214
editorView: RefObject<EditorView>,
192215
lineNumber: number,
@@ -422,25 +445,10 @@ export default function Diff({
422445
);
423446

424447
const compressButton = (
425-
<>
426-
<button
427-
className={styles.compressionToggle}
428-
onClick={() => {
429-
setCompressionEnabled(!compressionEnabled);
430-
}}
431-
title={
432-
compressionEnabled
433-
? "Do not compress streaks of matching lines"
434-
: "Compress streaks of matching lines"
435-
}
436-
>
437-
{compressionEnabled ? (
438-
<FoldIcon size={24} />
439-
) : (
440-
<UnfoldIcon size={24} />
441-
)}
442-
</button>
443-
</>
448+
<CompressToggleButton
449+
enabled={compressionEnabled}
450+
setEnabled={setCompressionEnabled}
451+
/>
444452
);
445453

446454
return (

0 commit comments

Comments
 (0)