Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getTextChange(list: MutationRecord[]): Delta | null {
const mutation = getTextChangeMutation(list);
if (!mutation || mutation.oldValue == null || mutation.target.nodeValue == null) return null;
const change = editor.delta();
const index = getNodeIndex(root, paper, mutation.target);
change.retain(index);
const diffs = diff(mutation.oldValue.replace(/\xA0/g, ' '), mutation.target.nodeValue.replace(/\xA0/g, ' '));
diffs.forEach(([ action, string ]) => {
if (action === diff.EQUAL) change.retain(string.length);
else if (action === diff.DELETE) change.delete(string.length);
else if (action === diff.INSERT) {
change.insert(string, editor.activeFormats);
}
});
change.chop();
return change;
}