@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
20 lines • 610 B
JavaScript
/**
* 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 const findChangedNodesFromTransaction = tr => {
const nodes = [];
const steps = tr.steps || [];
steps.forEach(step => {
step.getMap().forEach((_oldStart, _oldEnd, newStart, newEnd) => {
tr.doc.nodesBetween(newStart, Math.min(newEnd, tr.doc.content.size), node => {
if (!nodes.find(n => n === node)) {
nodes.push(node);
}
return false;
});
});
});
return nodes;
};