(before: string, after: string, maxEdits: number | undefined)
| 727 | |
| 728 | // The UTF-16 ranges of each line that differ from the other, ignoring a final `\n` |
| 729 | const inlineRanges = (before: string, after: string, maxEdits: number | undefined) => { |
| 730 | const inBefore: Array<readonly [number, number]> = [] |
| 731 | const inAfter: Array<readonly [number, number]> = [] |
| 732 | let i = 0 |
| 733 | let j = 0 |
| 734 | for (const edit of codePoints(withoutBreak(before), withoutBreak(after), { maxEdits })) { |
| 735 | let length = 0 |
| 736 | for (const item of edit.items) length += item.length |
| 737 | if (edit._tag === "Equal") { |
| 738 | i += length |
| 739 | j += length |
| 740 | } else if (edit._tag === "Delete") { |
| 741 | inBefore.push([i, i + length]) |
| 742 | i += length |
| 743 | } else { |
| 744 | inAfter.push([j, j + length]) |
| 745 | j += length |
| 746 | } |
| 747 | } |
| 748 | return [inBefore, inAfter] as const |
| 749 | } |
| 750 | |
| 751 | // Interns the tokens so the search compares integers instead of strings |
| 752 | const diffStrings = (a: ReadonlyArray<string>, b: ReadonlyArray<string>, maxEdits?: number) => { |
no test coverage detected