mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-26 19:56:49 +00:00
Add a very simple transaction builder for content replacements
This commit is contained in:
parent
cac9971299
commit
d978797fca
Notes:
Roan Kattouw
2012-03-08 23:21:21 +00:00
|
@ -1098,6 +1098,29 @@ ve.dm.DocumentNode.prototype.prepareRemoval = function( range ) {
|
|||
return tx;
|
||||
};
|
||||
|
||||
/**
|
||||
* Generates a transaction which removes content from a given range and
|
||||
* replaces it with other content.
|
||||
*
|
||||
* @param {ve.Range} range
|
||||
* @param {Array} content data
|
||||
* @returns {ve.dm.Transaction}
|
||||
*/
|
||||
ve.dm.DocumentNode.prototype.prepareContentReplacement = function( range, data ) {
|
||||
// TODO this is way too simple and doesn't verify that there's no structural changes being snuck in
|
||||
var tx = new ve.dm.Transaction();
|
||||
range.normalize();
|
||||
if ( range.start > 0 ) {
|
||||
tx.pushRetain( range.start );
|
||||
}
|
||||
tx.pushReplace( this.data.slice( range.start, range.end ), data );
|
||||
if ( range.end < this.data.length ) {
|
||||
tx.pushRetain( this.data.length - range.end );
|
||||
}
|
||||
|
||||
return tx;
|
||||
};
|
||||
|
||||
/**
|
||||
* Generates a transaction which annotates content within a given range.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue