Fix diffAndPrepareChanges (#1055)

pull/1059/head
jcgurango 2024-08-22 02:03:30 +08:00 committed by GitHub
parent 39b7cd4722
commit eeb54738f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 2 deletions

View File

@ -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;
}
}
return changes;
}