дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-27 13:06:07 +02:00
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.
Цей коміт міститься в:
1 джерело
1a7bf6efdc
коміт
4a14efc168
4 files changed
+55
-2
No files matched your search
@@ -45,6 +45,43 @@ test("side-by-side unchanged separators expand both panes from the keyboard", as
|
||||
await expect(left.locator(".cm-content")).toBeFocused();
|
||||
});
|
||||
|
||||
test("the first visible split diff frame has aligned line numbers and divider", async ({ workbench: page }) => {
|
||||
const frames = await page.evaluate(async () => {
|
||||
const left = Array.from({ length: 2500 }, (_, index) => `const item${index + 1} = ${index + 1};`).join("\n");
|
||||
const right = left.replace("const item2174 = 2174;", "const item2174 = 0;\nconst added = 1;");
|
||||
const actions = "/src/platform/actions.ts";
|
||||
const { executeAction } = await import(/* @vite-ignore */ actions);
|
||||
const samples = [];
|
||||
void executeAction("diff.compareTexts", {
|
||||
path: "items.ts",
|
||||
left: { text: left, label: "Before" },
|
||||
right: { text: right, label: "After" },
|
||||
});
|
||||
for (let frame = 0; frame < 120 && samples.length < 5; frame++) {
|
||||
await new Promise(requestAnimationFrame);
|
||||
const divider = document.querySelector(".cm-diffDivider");
|
||||
const panes = divider?.parentElement;
|
||||
if (!divider || !panes || getComputedStyle(panes).opacity === "0") continue;
|
||||
const origin = divider.getBoundingClientRect().top;
|
||||
const top = (selector: string) => {
|
||||
const element = panes.querySelector(selector);
|
||||
return element ? element.getBoundingClientRect().top - origin : undefined;
|
||||
};
|
||||
const line = top(".cm-merge-a .cm-diffLine-modified");
|
||||
const gutter = top(".cm-merge-a .cm-lineNumbers .cm-diffGutter-modified");
|
||||
const band = divider.querySelector<SVGPathElement>(".cm-diffBand");
|
||||
samples.push({ line, gutter, bandStart: band?.getPointAtLength(0).y, path: band?.getAttribute("d") });
|
||||
}
|
||||
return samples;
|
||||
});
|
||||
expect(frames).toHaveLength(5);
|
||||
const first = frames[0]!;
|
||||
expect(first.line).toBeDefined();
|
||||
expect(first.gutter).toBeCloseTo(first.line!, 0);
|
||||
expect(first.bandStart).toBeCloseTo(first.line!, 0);
|
||||
for (const frame of frames) expect(frame).toEqual(first);
|
||||
});
|
||||
|
||||
test("the unified separator stays legible in a narrow viewer and expands on click", async ({ workbench: page }) => {
|
||||
await page.setViewportSize({ width: 640, height: 650 });
|
||||
await openDiff(page, "unified");
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)",
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in new issue
Заблокувати користувача