MCPcopy
hub / github.com/inkeep/open-knowledge / applyFastDiff

Function applyFastDiff

packages/core/src/bridge/apply-diff.ts:40–62  ·  view source on GitHub ↗
(ytext: Y.Text, currentText: string, newText: string)

Source from the content-addressed store, hash-verified

38}
39
40export function applyFastDiff(ytext: Y.Text, currentText: string, newText: string): void {
41 if (currentText === newText) return;
42 if (
43 currentText.length > APPLY_FAST_DIFF_MAX_BYTES ||
44 newText.length > APPLY_FAST_DIFF_MAX_BYTES
45 ) {
46 applyByPrefixSuffixMiddleReplace(ytext, currentText, newText);
47 return;
48 }
49 const diffs = dmpDiff.diff_main(currentText, newText);
50 dmpDiff.diff_cleanupSemantic(diffs);
51 let offset = 0;
52 for (const [type, text] of diffs) {
53 if (type === 0) {
54 offset += text.length;
55 } else if (type === -1) {
56 ytext.delete(offset, text.length);
57 } else if (type === 1) {
58 ytext.insert(offset, text);
59 offset += text.length;
60 }
61 }
62}
63
64function applyByPrefixSuffixMiddleReplace(
65 ytext: Y.Text,

Callers 3

runObserverASyncImplFunction · 0.85
applyRenameWritesInlineFunction · 0.85
composeAndWriteRawBodyFunction · 0.85

Calls 3

deleteMethod · 0.80
insertMethod · 0.65

Tested by 1

applyRenameWritesInlineFunction · 0.68