r104180 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104179‎ | r104180 | r104181 >
Date:16:27, 24 November 2011
Author:catrope
Status:deferred
Tags:
Comment:
Fix bugs in prepareContentAnnotation() related to structural offsets, and add a test. Also add parenthesis to the if statement mixing || and &&, for clarity
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/models/es.DocumentModel.js (modified) (history)
  • /trunk/extensions/VisualEditor/tests/es/es.DocumentModel.test.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/tests/es/es.DocumentModel.test.js
@@ -258,7 +258,7 @@
259259 }
260260 } );
261261
262 -test( 'es.DocumentModel.prepareContentAnnotation', 2, function() {
 262+test( 'es.DocumentModel.prepareContentAnnotation', 3, function() {
263263 var documentModel = es.DocumentModel.newFromPlainObject( esTest.obj );
264264
265265 // Test 1
@@ -338,6 +338,31 @@
339339 ],
340340 'prepareContentAnnotation works across element boundaries'
341341 );
 342+
 343+ // Test 3
 344+ deepEqual(
 345+ documentModel.prepareContentAnnotation(
 346+ new es.Range( 4, 11 ), 'set', { 'type': 'textStyle/bold' }
 347+ ).getOperations(),
 348+ [
 349+ { 'type': 'retain', 'length': 9 },
 350+ {
 351+ 'type': 'annotate',
 352+ 'method': 'set',
 353+ 'bias': 'start',
 354+ 'annotation': { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }
 355+ },
 356+ { 'type': 'retain', 'length': 1 },
 357+ {
 358+ 'type': 'annotate',
 359+ 'method': 'set',
 360+ 'bias': 'stop',
 361+ 'annotation': { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }
 362+ },
 363+ { 'type': 'retain', 'length': 24 }
 364+ ],
 365+ 'prepareContentAnnotation works when given structural offsets'
 366+ );
342367 } );
343368
344369 test( 'es.DocumentModel.prepareRemoval', 11, function() {
Index: trunk/extensions/VisualEditor/modules/es/models/es.DocumentModel.js
@@ -1045,7 +1045,7 @@
10461046 }
10471047 var i = range.start,
10481048 span = i,
1049 - on = this.data[i].type !== undefined;
 1049+ on = false;
10501050 while ( i < range.end ) {
10511051 if ( this.data[i].type !== undefined ) {
10521052 // Don't annotate structural elements
@@ -1059,7 +1059,7 @@
10601060 }
10611061 } else {
10621062 var covered = es.DocumentModel.getIndexOfAnnotation( this.data[i], annotation ) !== -1;
1063 - if ( covered && method === 'set' || !covered && method === 'clear' ) {
 1063+ if ( ( covered && method === 'set' ) || ( !covered && method === 'clear' ) ) {
10641064 // Don't set/clear annotations on content that's already set/cleared
10651065 if ( on ) {
10661066 if ( span ) {
@@ -1084,10 +1084,10 @@
10851085 span++;
10861086 i++;
10871087 }
 1088+ if ( span ) {
 1089+ tx.pushRetain( span );
 1090+ }
10881091 if ( on ) {
1089 - if ( span ) {
1090 - tx.pushRetain( span );
1091 - }
10921092 tx.pushStopAnnotating( method, annotation );
10931093 }
10941094 if ( range.end < this.data.length ) {

Status & tagging log