From 34741f56c4edf7ab76c31dcfc78697a17f78fbc1 Mon Sep 17 00:00:00 2001 From: zhzhsx Date: Wed, 2 Dec 2026 14:37:23 +0800 Subject: [PATCH] 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 <1379025+zhzhsx@users.noreply.github.com> --- e2e/diff.spec.ts | 18 ++++++++++++++++++ src/features/vcs/cm.ts | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/e2e/diff.spec.ts b/e2e/diff.spec.ts index 1a83f6ac27..f5ef99e011 100644 --- a/e2e/diff.spec.ts +++ b/e2e/diff.spec.ts @@ -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"); }); }); diff --git a/src/features/vcs/cm.ts b/src/features/vcs/cm.ts index 4ff3aa4bdb..4d8dca88f7 100644 --- a/src/features/vcs/cm.ts +++ b/src/features/vcs/cm.ts @@ -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) },