UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

22 lines 703 B
/** * Finds all top level nodes affected by the transaction * Uses from/to positions in transaction's steps to work out which nodes will * be changed by the transaction */ export var findChangedNodesFromTransaction = function findChangedNodesFromTransaction(tr) { var nodes = []; var steps = tr.steps || []; steps.forEach(function (step) { step.getMap().forEach(function (_oldStart, _oldEnd, newStart, newEnd) { tr.doc.nodesBetween(newStart, Math.min(newEnd, tr.doc.content.size), function (node) { if (!nodes.find(function (n) { return n === node; })) { nodes.push(node); } return false; }); }); }); return nodes; };