r105962 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105961‎ | r105962 | r105963 >
Date:00:56, 13 December 2011
Author:inez
Status:deferred
Tags:
Comment:
Better implementation of history panel
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/models/es.SurfaceModel.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/sandbox/sandbox.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/models/es.SurfaceModel.js
@@ -33,6 +33,14 @@
3434 this.undoIndex = 0;
3535 };
3636
 37+es.SurfaceModel.prototype.getHistory = function() {
 38+ if ( this.smallStack.length > 0 ) {
 39+ return this.bigStack.slice(0).concat([{stack:this.smallStack.slice(0)}]);
 40+ } else {
 41+ return this.bigStack.slice(0);
 42+ }
 43+};
 44+
3745 /**
3846 * Gets the document model of the surface.
3947 *
Index: trunk/extensions/VisualEditor/modules/sandbox/sandbox.js
@@ -635,17 +635,23 @@
636636 '$': $( '#es-mode-history' ),
637637 '$panel': $( '#es-panel-history' ),
638638 'update': function() {
639 - function oneStack( stack, active ) {
640 - var operations,
641 - i,
642 - j,
643 - events = [],
644 - data;
 639+ var history = surfaceModel.getHistory(),
 640+ i = history.length,
 641+ end = Math.max( 0, i - 25 ),
 642+ j,
 643+ k,
 644+ ops,
 645+ events = '',
 646+ z = 0,
 647+ operations;
645648
646 - for ( i = 0; i < stack.length; i++) {
647 - operations = stack[i].getOperations().slice(0);
648 - for ( j = 0; j < operations.length; j++ ) {
649 - data = operations[j].data || operations[j].length;
 649+ while ( --i >= end ) {
 650+ z++;
 651+ operations = [];
 652+ for ( j = 0; j < history[i].stack.length; j++) {
 653+ ops = history[i].stack[j].getOperations().slice(0);
 654+ for ( k = 0; k < ops.length; k++ ) {
 655+ data = ops[k].data || ops[k].length;
650656 if ( es.isArray( data ) ) {
651657 data = data[0];
652658 if ( es.isArray( data ) ) {
@@ -655,37 +661,14 @@
656662 if ( typeof data !== 'string' && typeof data !== 'number' ) {
657663 data = '-';
658664 }
659 - operations[j] = operations[j].type.substr( 0, 3 ) + '(' + data + ')';
 665+ ops[k] = ops[k].type.substr( 0, 3 ) + '(' + data + ')';
660666 }
661 - events.push( '[' + operations.join( ', ' ) + ']' );
 667+ operations.push('[' + ops.join( ', ' ) + ']');
662668 }
663 - if ( active) {
664 - return '<div class="es-panel-history-active">' + events.join( ', ' ) + '</div>';
665 - } else {
666 - return '<div>' + events.join( ', ' ) + '</div>';
667 - }
 669+ events += '<div' + (z === surfaceModel.undoIndex ? ' class="es-panel-history-active"' : '') + '>' + operations.join(', ') + '</div>';
668670 }
669 -
670 - var events = '',
671 - i = surfaceModel.bigStack.length,
672 - j = 0,
673 - end;
674 -
675 - if ( surfaceModel.smallStack.length > 0 ) {
676 - events += oneStack( surfaceModel.smallStack );
677 - end = Math.max( 0, i - 24 );
678 - } else {
679 - end = Math.max( 0, i - 25 );
680 - }
681671
682 -
683 - while ( --i >= end ) {
684 - j++;
685 - events += oneStack( surfaceModel.bigStack[i].stack, surfaceModel.undoIndex === j);
686 - }
687 -
688672 this.$panel.html( events );
689 - return;
690673 }
691674 },
692675 'help': {

Status & tagging log