fix(diff): prevent layout jitter on load (#5600)

The side-by-side diff showed estimated gutter positions while CodeMirror measured the panes and the divider caught up. Collapsed unchanged rows get their final height immediately, and the panes and divider appear together after the first layout measurement.
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-11-24 21:10:16 +08:00
1 джерело 1a7bf6efdc
коміт 4a14efc168
4 files changed
+55 -2

No files matched your search

+4
Переглянути файл
@@ -355,6 +355,10 @@
.paneScroll :global(.cm-mergeViewEditor > .cm-editor > .cm-scroller) {
overflow: auto !important;
}
.measuringPanes {
opacity: 0;
}
.host :global(.cm-diffDivider) {
position: relative;
flex: none;
+2 -1
Переглянути файл
@@ -506,6 +506,7 @@ export const viewerTheme = EditorView.theme(
".cm-collapsedLines": {
WebkitUserSelect: "none",
userSelect: "none",
minHeight: "max(27px, var(--openidea-editor-line-height, var(--lh-code)))",
padding: "0",
background: "var(--bg-editor)",
},
@@ -514,7 +515,7 @@ export const viewerTheme = EditorView.theme(
alignItems: "center",
gap: "var(--space-1)",
width: "100%",
minHeight: "max(27px, var(--openidea-editor-line-height, var(--lh-code)))",
minHeight: "inherit",
padding: "0 var(--space-3)",
color: "var(--fg-secondary)",
fontFamily: "var(--font-ui)",
+12 -1
Переглянути файл
@@ -10,6 +10,7 @@ import { Decoration, EditorView, ViewPlugin, type DecorationSet, type ViewUpdate
import { getChunks, type Chunk, type MergeView } from "@codemirror/merge";
import { changedLineGutters, chunkKind, type DiffKind } from "./cm";
import { arrowButton } from "./diffControls";
import styles from "./DiffEditor.module.css";
type Side = "a" | "b";
@@ -435,7 +436,17 @@ export class UnalignedPanes implements DiffPanes {
this.resize = new ResizeObserver(() => this.schedule());
this.resize.observe(this.divider);
}
requestAnimationFrame(() => this.resync());
const editors = this.divider.parentElement!;
const measuring = styles.measuringPanes!;
editors.classList.add(measuring);
// Both editors have queued their initial measurements. Reveal the panes with the first divider
// drawing after those measurements, so estimated gutter positions never reach the screen.
this.frame = requestAnimationFrame(() => {
if (this.sync) this.follow("b");
this.draw();
editors.classList.remove(measuring);
});
this.cleanup.push(() => editors.classList.remove(measuring));
}
/** Brings the left pane in line with the right one. */