| 561 | } |
| 562 | |
| 563 | function 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 | |
| 589 | function anchorMatchesAt(renderedText: string, start: number, oldSubstring: string, textAnchor: TextEditAnchor): boolean { |
| 590 | const oldLength = textAnchor.end - textAnchor.start; |