r95049 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95048‎ | r95049 | r95050 >
Date:23:00, 19 August 2011
Author:inez
Status:deferred
Tags:
Comment:
Make sure that we are not creating empty annotations arrays during serialization
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.Content.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.Content.js
@@ -658,23 +658,29 @@
659659 *
660660 * @method
661661 */
662 -es.Content.prototype.handleAnnotation = function( bias, stack, index, annotation ) {
 662+es.Content.prototype.handleAnnotation = function( bias, line, index, annotation ) {
663663 if ( bias === 'open' ) {
664664 var newAnnotation = es.copyObject( annotation );
665665 newAnnotation.range = {
666666 start: index
667667 };
668 - stack.push( newAnnotation );
 668+ if ( !line.annotations ) {
 669+ line.annotations = [ newAnnotation ];
 670+ } else {
 671+ line.annotations.push( newAnnotation );
 672+ }
669673 } else {
670 - for ( var i = stack.length - 1; i >= 0; i-- ) {
671 - if ( !stack[i].range.end ) {
672 - if ( annotation ) {
673 - if ( stack[i].type === annotation.type && es.compareObjects( stack[i].data, annotation.data ) ) {
674 - stack[i].range.end = index;
675 - break;
 674+ if ( line.annotations ) {
 675+ for ( var i = line.annotations.length - 1; i >= 0; i-- ) {
 676+ if ( !line.annotations[i].range.end ) {
 677+ if ( annotation ) {
 678+ if ( line.annotations[i].type === annotation.type && es.compareObjects( line.annotations[i].data, annotation.data ) ) {
 679+ line.annotations[i].range.end = index;
 680+ break;
 681+ }
 682+ } else {
 683+ line.annotations[i].range.end = index;
676684 }
677 - } else {
678 - stack[i].range.end = index;
679685 }
680686 }
681687 }
@@ -700,7 +706,7 @@
701707 for ( i = 0; i < this.data.length; i++ ) {
702708
703709 if ( line == null ) {
704 - line = { text : '', annotations : [] };
 710+ line = { text : '' };
705711 }
706712
707713 right = this.data[i];
@@ -708,7 +714,7 @@
709715 rightPlain = typeof right === 'string';
710716
711717 if ( rightPlain && right == "\n" ) {
712 - this.handleAnnotation( 'close', line.annotations, i - offset );
 718+ this.handleAnnotation( 'close', line, i - offset );
713719 lines.push(line);
714720 line = null;
715721 offset = i + 1;
@@ -718,22 +724,22 @@
719725
720726 if ( !leftPlain && rightPlain ) {
721727 // [formatted][plain] pair, close any annotations for left
722 - this.handleAnnotation( 'close', line.annotations, i - offset );
 728+ this.handleAnnotation( 'close', line, i - offset );
723729 } else if ( leftPlain && !rightPlain ) {
724730 // [plain][formatted] pair, open any annotations for right
725731 for ( j = 1; j < right.length; j++ ) {
726 - this.handleAnnotation( 'open', line.annotations, i - offset, right[j] );
 732+ this.handleAnnotation( 'open', line, i - offset, right[j] );
727733 }
728734 } else if ( !leftPlain && !rightPlain ) {
729735 // [formatted][formatted] pair, open/close any differences
730736 for ( j = 1; j < left.length; j++ ) {
731737 if ( this.indexOfAnnotation( i , left[j], true ) === -1 ) {
732 - this.handleAnnotation( 'close', line.annotations, i - offset, left[j] );
 738+ this.handleAnnotation( 'close', line, i - offset, left[j] );
733739 }
734740 }
735741 for ( j = 1; j < right.length; j++ ) {
736742 if ( this.indexOfAnnotation( i - 1, right[j], true ) === -1 ) {
737 - this.handleAnnotation( 'open', line.annotations, i - offset, right[j] );
 743+ this.handleAnnotation( 'open', line, i - offset, right[j] );
738744 }
739745 }
740746 }
@@ -743,7 +749,7 @@
744750 }
745751
746752 if ( line != null ) {
747 - this.handleAnnotation( 'close', line.annotations, i - offset );
 753+ this.handleAnnotation( 'close', line, i - offset );
748754 lines.push( line );
749755 }
750756 return lines;

Status & tagging log