Skip to content

Commit

Permalink
Fix diffAndPrepareChanges (#1055)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcgurango authored Aug 21, 2024
1 parent 39b7cd4 commit eeb5473
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions web/cm_util.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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;
}

0 comments on commit eeb5473

Please sign in to comment.