MCPcopy Create free account
hub / github.com/donghaxkim/react-rewrite / findTextDiff

Function findTextDiff

packages/cli/src/mdx-text.ts:563–587  ·  view source on GitHub ↗
(oldText: string, newText: string)

Source from the content-addressed store, hash-verified

561}
562
563function findTextDiff(oldText: string, newText: string): TextDiff | null {
564 if (oldText === newText) return null;
565
566 let prefixLen = 0;
567 while (prefixLen < oldText.length && prefixLen < newText.length && oldText[prefixLen] === newText[prefixLen]) {
568 prefixLen++;
569 }
570
571 let oldSuffixStart = oldText.length;
572 let newSuffixStart = newText.length;
573 while (
574 oldSuffixStart > prefixLen &&
575 newSuffixStart > prefixLen &&
576 oldText[oldSuffixStart - 1] === newText[newSuffixStart - 1]
577 ) {
578 oldSuffixStart--;
579 newSuffixStart--;
580 }
581
582 const oldSubstring = oldText.slice(prefixLen, oldSuffixStart);
583 const newSubstring = newText.slice(prefixLen, newSuffixStart);
584
585 if (!oldSubstring && !newSubstring) return null;
586 return { oldSubstring, newSubstring, prefixLen };
587}
588
589function anchorMatchesAt(renderedText: string, start: number, oldSubstring: string, textAnchor: TextEditAnchor): boolean {
590 const oldLength = textAnchor.end - textAnchor.start;

Callers 1

applyMdxTextEditFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected