http://www.mediawiki.org/wiki/Special:Code/MediaWiki/94982
Revision: 94982
Author: tparscal
Date: 2011-08-19 02:22:14 +0000 (Fri, 19 Aug 2011)
Log Message:
-----------
Partially done with selection and mutation changes - transactions will be
document-relative soon
Modified Paths:
--------------
trunk/parsers/wikidom/lib/es/es.Selection.js
Added Paths:
-----------
trunk/parsers/wikidom/lib/es/es.Mutation.js
Added: trunk/parsers/wikidom/lib/es/es.Mutation.js
===================================================================
--- trunk/parsers/wikidom/lib/es/es.Mutation.js (rev 0)
+++ trunk/parsers/wikidom/lib/es/es.Mutation.js 2011-08-19 02:22:14 UTC (rev
94982)
@@ -0,0 +1,15 @@
+es.Mutation = function( transactions ) {
+ this.transactions = transactions || [];
+};
+
+es.Mutation.prototype.add = function( id, transaction ) {
+ this.transactions.push( { 'block': id, 'transaction': transaction } );
+};
+
+es.Mutation.prototype.commit = function() {
+
+};
+
+es.Mutation.prototype.rollback = function() {
+
+};
Property changes on: trunk/parsers/wikidom/lib/es/es.Mutation.js
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: trunk/parsers/wikidom/lib/es/es.Selection.js
===================================================================
--- trunk/parsers/wikidom/lib/es/es.Selection.js 2011-08-19 02:18:08 UTC
(rev 94981)
+++ trunk/parsers/wikidom/lib/es/es.Selection.js 2011-08-19 02:22:14 UTC
(rev 94982)
@@ -28,8 +28,7 @@
* @method
*/
es.Selection.prototype.normalize = function() {
- if ( this.from.block.getIndex() < this.to.block.getIndex()
- || ( this.from.block === this.to.block &&
this.from.offset < this.to.offset ) ) {
+ if ( this.from.compareWith( this.to ) < 1 ) {
this.start = this.from;
this.end = this.to;
} else {
@@ -38,22 +37,80 @@
}
};
-/**
- * Gets all blocks selected completely, between from and to.
- *
- * If from and to are adjacent blocks, or the same block, the result will
always be an empty array.
- *
- * @method
- * @returns {Array} List of blocks
- */
-es.Selection.prototype.through = function() {
- var through = [];
- if ( this.from !== this.to && this.from.nextBlock() !== this.to ) {
- var next = this.from.nextBlock();
- while ( next && next !== this.to ) {
- through.push( next );
- next = next.nextBlock();
+es.Selection.prototype.prepareInsert = function( content ) {
+ this.normalize();
+ if ( this.start ) {
+ var mutation;
+ if ( this.end && this.start.compareWith( end ) < 0 ) {
+ mutation = this.prepareRemove();
+ } else {
+ mutation = new es.Mutation();
}
+ mutation.add( this.start.block.getId(),
this.start.block.prepareInsert( content ) );
+ return mutation;
}
- return through;
+ throw 'Mutation preparation error. Can not insert content at undefined
location.';
};
+
+es.Selection.prototype.prepareRemove = function() {
+ this.normalize();
+ var mutation = new es.Mutation();
+ if ( this.start.block === this.end.block ) {
+ // Single block deletion
+ mutation.add(
+ this.start.block.getId(),
+ this.start.block.prepareRemove( new es.Range(
this.start.offset, this.end.offset ) )
+ );
+ } else {
+ // Multiple block deletion
+ var block = this.start.block.next();
+ // First
+ mutation.add(
+ block.getId(),
+ block.prepareRemove( new es.Range( this.start.offset,
block.getLength() ) )
+ );
+ while ( ( block = block.next() ) !== this.end.block ) {
+ // Middle
+ mutation.add(
+ block.getId(), block.prepareRemove( new
es.Range( 0, block.getLength() ) )
+ );
+ }
+ // Last
+ mutation.add( block.getId(), block.prepareRemove( new es.Range(
0, this.end.offset ) ) );
+ }
+ return mutation;
+};
+
+es.Selection.prototype.prepareAnnotate = function() {
+ this.normalize();
+ var mutation = new es.Mutation();
+ if ( this.start.block === this.end.block ) {
+ // Single block annotation
+ mutation.add(
+ this.start.block.getId(),
+ this.start.block.prepareRemove( new es.Range(
this.start.offset, this.end.offset ) )
+ );
+ } else {
+ // Multiple block annotation
+ var block = this.start.block.next();
+ // First
+ mutation.add(
+ block.getId(),
+ block.prepareAnnotate(
+ annotation, new es.Range( this.start.offset,
block.getLength() )
+ )
+ );
+ while ( ( block = block.next() ) !== this.end.block ) {
+ // Middle
+ mutation.add(
+ block.getId(),
+ block.prepareAnnotate( annotation, new
es.Range( 0, block.getLength() ) )
+ );
+ }
+ // Last
+ mutation.add(
+ block.getId(), block.prepareAnnotate( annotation, new
es.Range( 0, this.end.offset ) )
+ );
+ }
+ return mutation;
+};
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs