Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

pullRequestDiffFold.ts

25 lines823 Bytes

1export type DiffFoldOverride = "expanded" | "folded" | null;
2​
3/** The reader's own fold choice per file. It is absolute, so a Viewed mark loading later keeps it. */
4export type FileDiffFoldChoices = ReadonlyMap<string, boolean>;
5​
6export function isFileDiffCollapsed(
7 fileKey: string,
8 foldOverride: DiffFoldOverride,
9 choices: FileDiffFoldChoices,
10 viewed = false,
11): boolean {
12 return choices.get(fileKey) ?? (foldOverride === null ? viewed : foldOverride === "folded");
14​
15export function withFileDiffFold(
16 choices: FileDiffFoldChoices,
17 fileKey: string,
18 collapsed: boolean | undefined,
19): FileDiffFoldChoices {
20 if (choices.get(fileKey) === collapsed) return choices;
21 const next = new Map(choices);
22 if (collapsed === undefined) next.delete(fileKey);
23 else next.set(fileKey, collapsed);
24 return next;