Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/docs/app/(diffs)/docs/Editor/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1053,10 +1053,12 @@ const file: FileContents | undefined = editor.getFile();
// Full document text, or '' when nothing is attached.
const text: string = editor.getText();

// Snapshot selections and scroll position for persistence or remount restore.
// Snapshot selections, active folds, and scroll position for persistence or
// remount restore.
const state: EditorState = editor.getState();
// EditorState = {
// selections?: EditorSelection[];
// foldRanges?: LineRange[]; // zero-based; standalone closers stay visible
// view?: { scrollLeft: number; scrollTop: number };
// }

Expand Down
30 changes: 30 additions & 0 deletions packages/diffs/src/components/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type {
FileContents,
HighlightedToken,
LineAnnotation,
LineRange,
PostRenderPhase,
PrePropertiesConfig,
RenderFileMetadata,
Expand Down Expand Up @@ -176,6 +177,7 @@ export class File<
public file: FileContents | undefined;
protected renderRange: RenderRange | undefined;
protected enabled = true;
protected foldRanges: LineRange[] = [];

protected editor: DiffsEditor<LAnnotation> | undefined;

Expand Down Expand Up @@ -214,6 +216,33 @@ export class File<
return this.file;
}

public __setFoldRanges(ranges: LineRange[]): void {
if (!this.updateFoldRanges(ranges)) {
return;
}
if (this.enabled && this.file != null) {
this.rerender();
}
}

protected updateFoldRanges(ranges: LineRange[]): boolean {
if (
ranges.length === this.foldRanges.length &&
ranges.every((range, index) => {
const previous = this.foldRanges[index];
return (
previous?.startLine === range.startLine &&
previous.endLine === range.endLine
);
})
) {
return false;
}
this.foldRanges = ranges.map((range) => ({ ...range }));
this.fileRenderer.setFoldRanges(this.foldRanges);
return true;
}

public onThemeChange(): void {
this.fileRenderer.clearRenderCache();
this.rerender();
Expand Down Expand Up @@ -373,6 +402,7 @@ export class File<
this.workerManager = undefined;
this.file = undefined;
}
this.foldRanges = [];

this.enabled = false;

Expand Down
Loading