From 14cdf39afb9a00d75e49eaa6c57c2b31223c968a Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Wed, 14 Oct 2026 14:30:07 +0400 Subject: [PATCH] refac --- .../components/common/DiffEditorModal.svelte | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/lib/components/common/DiffEditorModal.svelte b/src/lib/components/common/DiffEditorModal.svelte index 8387a98940..ed5f1bc08e 100644 --- a/src/lib/components/common/DiffEditorModal.svelte +++ b/src/lib/components/common/DiffEditorModal.svelte @@ -46,6 +46,7 @@ let activeChunk = 0; let overview: ReturnType = []; let chunkCount = 0; + let lineNumberDigits = 1; let lineChanges = { removed: 0, added: 0 }; let copied: { side: 'a' | 'b'; text: string } | null = null; let approximate = false; @@ -111,6 +112,7 @@ working = merge.a.state.doc.toString(); proposal = merge.b.state.doc.toString(); chunkCount = merge.chunks.length; + lineNumberDigits = String(Math.max(merge.a.state.doc.lines, merge.b.state.doc.lines)).length; lineChanges = changedLineCounts(merge.a.state.doc, merge.b.state.doc, merge.chunks); overview = chunkOverview(merge.a.state.doc, merge.b.state.doc, merge.chunks); approximate = merge.chunks.some((chunk) => !chunk.precise); @@ -177,6 +179,7 @@ let disposed = false; let view: MergeView | null = null; let observer: MutationObserver | undefined; + let alignmentFrame = 0; const themes = [new Compartment(), new Compartment()]; const language = [new Compartment(), new Compartment()]; const path = session?.path; @@ -193,6 +196,13 @@ language[index].of([]), EditorView.updateListener.of((update) => { if (update.docChanged || update.selectionSet) refresh(update, side); + if ((update.heightChanged || update.viewportChanged) && !alignmentFrame) { + // Align after both virtualized editors have measured their visible lines. + alignmentFrame = requestAnimationFrame(() => { + alignmentFrame = 0; + if (!disposed) view?.reconfigure({}); + }); + } }), EditorView.theme({ '&': { fontSize: '0.75rem' }, @@ -239,6 +249,7 @@ return { destroy: () => { disposed = true; + cancelAnimationFrame(alignmentFrame); observer?.disconnect(); view?.destroy(); if (merge === view) merge = null; @@ -384,7 +395,11 @@ {/each} {#if comparing} -
+
{:else}