mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-27 15:50:29 +00:00
Edit check: add helper to BaseEditCheck to find added nodes
Change-Id: Ia6e2d97b57c002f9cea2167c64f960f1422dabfe
This commit is contained in:
parent
2c73af983e
commit
34030accdb
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue