fix(diff): align the deleted lines with the new ones in the unified view (#7404)

In the unified diff viewer a deleted block started 3.5px right of the added lines: @codemirror/merge insets .cm-deletedChunk by 6px while the viewer's lines use LINE_INSET (2.5px). The block now uses LINE_INSET, which also fixes the base lines on the merge editor's sides.

Co-authored-by: zhzhsx <[email protected]>
Цей коміт міститься в:
zhzhsxтаzhzhsx authored and GitHub committed 2026-12-02 14:37:23 +08:00
1 джерело 2907832e37
коміт 34741f56c4
2 files changed
+21 -1

No files matched your search

+18
Переглянути файл
@@ -237,6 +237,24 @@ test.describe("small cases (side-by-side, Highlight words)", () => {
const { b, deletedChunks } = await rendered(page);
expect(deletedChunks).toBe(1);
expect(b.lines).toEqual(all(6, "inserted"));
// Old and new lines share the editor's text column: the deleted block must not sit to its right.
const edges = await page.evaluate(() => {
const textLeft = (el: Element | null | undefined) => {
const node = el && document.createTreeWalker(el, NodeFilter.SHOW_TEXT).nextNode();
if (!node) return null;
const range = document.createRange();
range.setStart(node, 0);
range.setEnd(node, 1);
return range.getBoundingClientRect().left;
};
return {
deleted: textLeft(document.querySelector(".cm-deletedChunk .cm-deletedLine")),
inserted: textLeft(document.querySelector(".cm-line.cm-diffLine-inserted")),
};
});
expect(edges.deleted).not.toBeNull();
expect(edges.inserted).not.toBeNull();
expect(Math.abs(edges.deleted! - edges.inserted!)).toBeLessThan(0.5);
await shot(page, "options-unified");
});
});
+3 -1
Переглянути файл
@@ -494,7 +494,9 @@ export const viewerTheme = EditorView.theme(
},
// The unified view: old lines deleted, new lines inserted. The old lines of a chunk whose words
// were compared sit right above its first new line and take the lighter colour too.
".cm-deletedChunk": { backgroundColor: diffTint("deleted", 70) },
// The library's own 6px `paddingLeft` on this block would start the old lines 3.5px right of
// the new ones (`.cm-line` insets `LINE_INSET`); keep both at the same column.
".cm-deletedChunk": { backgroundColor: diffTint("deleted", 70), paddingLeft: `${LINE_INSET}px` },
"&.cm-diffWords .cm-deletedChunk:has(+ .cm-diffLine-fine)": { backgroundColor: diffTint("deleted", 28) },
// Full line height, as `.cm-diffWord`.
".cm-deletedChunk .cm-deletedText": { display: "inline-block", background: diffTint("deleted", 85) },