https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113422
Revision: 113422
Author: catrope
Date: 2012-03-08 23:21:21 +0000 (Thu, 08 Mar 2012)
Log Message:
-----------
Add a very simple transaction builder for content replacements
Modified Paths:
--------------
trunk/extensions/VisualEditor/modules/ve/dm/nodes/ve.dm.DocumentNode.js
Modified:
trunk/extensions/VisualEditor/modules/ve/dm/nodes/ve.dm.DocumentNode.js
===================================================================
--- trunk/extensions/VisualEditor/modules/ve/dm/nodes/ve.dm.DocumentNode.js
2012-03-08 23:21:20 UTC (rev 113421)
+++ trunk/extensions/VisualEditor/modules/ve/dm/nodes/ve.dm.DocumentNode.js
2012-03-08 23:21:21 UTC (rev 113422)
@@ -1099,6 +1099,29 @@
};
/**
+ * 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.
*
* @method
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs