Edit check: add helper to BaseEditCheck to find added nodes

Change-Id: Ia6e2d97b57c002f9cea2167c64f960f1422dabfe
This commit is contained in:
David Lynch 2024-11-25 10:47:56 -06:00
parent 2c73af983e
commit 34030accdb

View file

@ -107,6 +107,26 @@ mw.editcheck.BaseEditCheck.prototype.getModifiedContentRanges = function ( docum
return this.getModifiedRanges( documentModel, this.constructor.static.onlyCoveredNodes, true );
};
/**
* Find nodes that were added during the edit session
*
* @param {ve.dm.Document} documentModel
* @param {string} [type] Type of nodes to find, or all nodes if false
* @return {ve.dm.Node[]}
*/
mw.editcheck.BaseEditCheck.prototype.getAddedNodes = function ( documentModel, type ) {
const matchedNodes = [];
this.getModifiedRanges( documentModel ).forEach( ( range ) => {
const nodes = documentModel.selectNodes( range, 'covered' );
nodes.forEach( ( node ) => {
if ( !type || node.node.getType() === type ) {
matchedNodes.push( node.node );
}
} );
} );
return matchedNodes;
};
/**
* Get content ranges which have been inserted
*