r103859 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103858‎ | r103859 | r103860 >
Date:22:59, 21 November 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Installed HistoryModel into SurfaceView
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/models/es.HistoryModel.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/models/es.HistoryModel.js
@@ -78,10 +78,10 @@
7979 var absLengthDiff = Math.abs( transaction.getLengthDiff() );
8080 // Unless we should intentionally accumulate transactions or this is the first one for this
8181 // state, automatically push state
82 - if ( !accumulate && !this.transactions.length ) {
 82+ if ( !accumulate && this.transactions.length ) {
8383 if (
8484 // If the transactions are of a different type
85 - this.transactions[this.transactions.length].type !== transaction.type ||
 85+ this.transactions[this.transactions.length - 1].type !== transaction.type ||
8686 // This transaction would make the state longer than the maximum length
8787 this.transactionsDiff + absLengthDiff > this.maxTransactionsDiff
8888 ) {
@@ -168,3 +168,7 @@
169169 }
170170 }
171171 };
 172+
 173+/* Inheritance */
 174+
 175+es.extendClass( es.HistoryModel, es.EventEmitter );
Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js
@@ -45,6 +45,9 @@
4646 this.documentView = new es.DocumentView( this.model.getDocument(), this );
4747 this.$.append( this.documentView.$ );
4848
 49+ // History
 50+ this.history = new es.HistoryModel( this.documentView.getModel() );
 51+
4952 // Interaction state
5053
5154 // There are three different selection modes available for mouse. Selection of:
@@ -164,7 +167,7 @@
165168 } else if ( e.originalEvent.detail === 2 ) { // double click
166169 this.mouse.selectingMode = 2; // used in mouseMove handler
167170
168 - var wordRange = this.documentView.model.getWordBoundaries( offset );
 171+ var wordRange = this.documentView.getModel().getWordBoundaries( offset );
169172 if( wordRange ) {
170173 this.selection = wordRange;
171174 this.mouse.selectedRange = this.selection.clone();
@@ -211,7 +214,7 @@
212215 if ( this.mouse.selectingMode === 1 ) { // selection of chars
213216 this.selection.to = offset;
214217 } else if ( this.mouse.selectingMode === 2 ) { // selection of words
215 - var wordRange = this.documentView.model.getWordBoundaries( offset );
 218+ var wordRange = this.documentView.getModel().getWordBoundaries( offset );
216219 if ( wordRange ) {
217220 if ( wordRange.to <= this.mouse.selectedRange.from ) {
218221 this.selection.from = wordRange.from;
@@ -410,15 +413,15 @@
411414 if ( sourceNode === targetNode ||
412415 ( typeof sourceSplitableNode !== 'undefined' &&
413416 sourceSplitableNode.getParent() === targetSplitableNode.getParent() ) ) {
414 - tx = this.documentView.model.prepareRemoval(
 417+ tx = this.documentView.getModel().prepareRemoval(
415418 new es.Range( targetOffset, sourceOffset )
416419 );
417 - this.documentView.model.commit ( tx );
 420+ this.history.commit( tx );
418421 } else {
419 - tx = this.documentView.model.prepareInsertion(
 422+ tx = this.documentView.getModel().prepareInsertion(
420423 targetOffset, sourceNode.model.getContent()
421424 );
422 - this.documentView.model.commit( tx );
 425+ this.history.commit( tx );
423426
424427 var nodeToDelete = sourceNode;
425428 es.DocumentNode.traverseUpstream( nodeToDelete, function( node ) {
@@ -431,13 +434,13 @@
432435 var range = new es.Range();
433436 range.from = this.documentView.getOffsetFromNode( nodeToDelete, false );
434437 range.to = range.from + nodeToDelete.getElementLength();
435 - tx = this.documentView.model.prepareRemoval( range );
436 - this.documentView.model.commit ( tx );
 438+ tx = this.documentView.getModel().prepareRemoval( range );
 439+ this.history.commit( tx );
437440 }
438441 } else {
439442 // selection removal
440 - tx = this.documentView.model.prepareRemoval( this.selection );
441 - this.documentView.model.commit( tx );
 443+ tx = this.documentView.getModel().prepareRemoval( this.selection );
 444+ this.history.commit( tx );
442445 this.documentView.clearSelection();
443446 this.selection.from = this.selection.to = this.selection.start;
444447 this.showCursor();
@@ -499,14 +502,14 @@
500503 if ( val.length > 0 ) {
501504 var tx;
502505 if ( this.selection.from != this.selection.to ) {
503 - tx = this.documentView.model.prepareRemoval( this.selection );
504 - this.documentView.model.commit( tx );
 506+ tx = this.documentView.getModel().prepareRemoval( this.selection );
 507+ this.history.commit( tx );
505508 this.documentView.clearSelection();
506509 this.selection.from = this.selection.to =
507510 Math.min( this.selection.from, this.selection.to );
508511 }
509 - tx = this.documentView.model.prepareInsertion( this.selection.from, val.split('') );
510 - this.documentView.model.commit ( tx );
 512+ tx = this.documentView.getModel().prepareInsertion( this.selection.from, val.split('') );
 513+ this.history.commit( tx );
511514 this.selection.from += val.length;
512515 this.selection.to += val.length;
513516 this.showCursor();
@@ -541,7 +544,7 @@
542545 direction === 'left' ? -1 : 1
543546 );
544547 if ( unit === 'word' ) {
545 - var wordRange = this.documentView.model.getWordBoundaries(
 548+ var wordRange = this.documentView.getModel().getWordBoundaries(
546549 direction === 'left' ? to : offset
547550 );
548551 if ( wordRange ) {
@@ -565,7 +568,7 @@
566569 switch ( unit ) {
567570 case 'unit':
568571 var toNode = null;
569 - this.documentView.model.traverseLeafNodes(
 572+ this.documentView.getModel().traverseLeafNodes(
570573 function( node ) {
571574 if ( toNode === null) {
572575 toNode = node;
@@ -577,7 +580,7 @@
578581 this.documentView.getNodeFromOffset( this.selection.to, false ).getModel(),
579582 direction === 'up' ? true : false
580583 );
581 - to = this.documentView.model.getOffsetFromNode( toNode, false ) + 1;
 584+ to = this.documentView.getModel().getOffsetFromNode( toNode, false ) + 1;
582585 break;
583586 case 'char':
584587 /*

Status & tagging log