MCPcopy Create free account
hub / github.com/Effect-TS/effect / inlineRanges

Function inlineRanges

packages/effect/src/TextDiff.ts:729–749  ·  view source on GitHub ↗
(before: string, after: string, maxEdits: number | undefined)

Source from the content-addressed store, hash-verified

727
728// The UTF-16 ranges of each line that differ from the other, ignoring a final `\n`
729const 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
752const diffStrings = (a: ReadonlyArray<string>, b: ReadonlyArray<string>, maxEdits?: number) => {

Callers 1

hunksFunction · 0.85

Calls 3

withoutBreakFunction · 0.85
codePointsFunction · 0.70
pushMethod · 0.65

Tested by

no test coverage detected