From eeb54738f25e825d33c133323ac1f427288e1054 Mon Sep 17 00:00:00 2001 From: jcgurango Date: Thu, 22 Aug 2024 02:03:30 +0800 Subject: [PATCH] Fix diffAndPrepareChanges (#1055) --- web/cm_util.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/web/cm_util.ts b/web/cm_util.ts index d958afa2..2fdc4bcd 100644 --- a/web/cm_util.ts +++ b/web/cm_util.ts @@ -1,4 +1,4 @@ -import diff, { DELETE, INSERT } from "fast-diff"; +import diff, { DELETE, EQUAL, INSERT } from "fast-diff"; import type { ChangeSpec } from "@codemirror/state"; export function diffAndPrepareChanges( @@ -14,10 +14,12 @@ export function diffAndPrepareChanges( for (const part of diffs) { if (part[0] === INSERT) { changes.push({ from: startIndex, insert: part[1] }); + } else if (part[0] === EQUAL) { + startIndex += part[1].length; } else if (part[0] === DELETE) { changes.push({ from: startIndex, to: startIndex + part[1].length }); + startIndex += part[1].length; } - startIndex += part[1].length; } return changes; }