@sanity/diff-match-patch
Advanced tools
Comparing version 0.0.7 to 0.0.8
import { cleanupSemantic, cleanupEfficiency } from '../diff/cleanup.js'; | ||
import { diff, DiffType } from '../diff/diff.js'; | ||
import { diffText1 } from '../diff/diffText.js'; | ||
import { isLowSurrogate } from '../utils/surrogatePairs.js'; | ||
import { MAX_BITS } from './constants.js'; | ||
@@ -158,3 +159,8 @@ import { createPatchObject } from './createPatchObject.js'; | ||
// Add the prefix. | ||
const prefix = text.substring(patch.start2 - padding, patch.start2); | ||
// Avoid splitting inside a surrogate. | ||
let prefixStart = patch.start2 - padding; | ||
if (prefixStart >= 1 && isLowSurrogate(text[prefixStart])) { | ||
prefixStart--; | ||
} | ||
const prefix = text.substring(prefixStart, patch.start2); | ||
if (prefix) { | ||
@@ -164,3 +170,8 @@ patch.diffs.unshift([DiffType.EQUAL, prefix]); | ||
// Add the suffix. | ||
const suffix = text.substring(patch.start2 + patch.length1, patch.start2 + patch.length1 + padding); | ||
// Avoid splitting inside a surrogate. | ||
let suffixEnd = patch.start2 + patch.length1 + padding; | ||
if (suffixEnd < text.length && isLowSurrogate(text[suffixEnd])) { | ||
suffixEnd++; | ||
} | ||
const suffix = text.substring(patch.start2 + patch.length1, suffixEnd); | ||
if (suffix) { | ||
@@ -167,0 +178,0 @@ patch.diffs.push([DiffType.EQUAL, suffix]); |
{ | ||
"name": "@sanity/diff-match-patch", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Robust diff, match and patch algorithms to perform operations required for synchronizing plain text", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
import { cleanupSemantic, cleanupEfficiency } from '../diff/cleanup.js' | ||
import { diff, Diff, DiffType } from '../diff/diff.js' | ||
import { diffText1 } from '../diff/diffText.js' | ||
import { isLowSurrogate } from '../utils/surrogatePairs.js' | ||
import { MAX_BITS } from './constants.js' | ||
@@ -203,11 +204,23 @@ import { createPatchObject, Patch } from './createPatchObject.js' | ||
// Add the prefix. | ||
const prefix = text.substring(patch.start2 - padding, patch.start2) | ||
// Avoid splitting inside a surrogate. | ||
let prefixStart = patch.start2 - padding | ||
if (prefixStart >= 1 && isLowSurrogate(text[prefixStart])) { | ||
prefixStart-- | ||
} | ||
const prefix = text.substring(prefixStart, patch.start2) | ||
if (prefix) { | ||
patch.diffs.unshift([DiffType.EQUAL, prefix]) | ||
} | ||
// Add the suffix. | ||
const suffix = text.substring( | ||
patch.start2 + patch.length1, | ||
patch.start2 + patch.length1 + padding, | ||
) | ||
// Avoid splitting inside a surrogate. | ||
let suffixEnd = patch.start2 + patch.length1 + padding | ||
if (suffixEnd < text.length && isLowSurrogate(text[suffixEnd])) { | ||
suffixEnd++ | ||
} | ||
const suffix = text.substring(patch.start2 + patch.length1, suffixEnd) | ||
if (suffix) { | ||
@@ -214,0 +227,0 @@ patch.diffs.push([DiffType.EQUAL, suffix]) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
471824
8089