Index: trunk/extensions/VisualEditor/tests/es/es.DocumentModel.test.js |
— | — | @@ -258,7 +258,7 @@ |
259 | 259 | } |
260 | 260 | } ); |
261 | 261 | |
262 | | -test( 'es.DocumentModel.prepareContentAnnotation', 2, function() { |
| 262 | +test( 'es.DocumentModel.prepareContentAnnotation', 3, function() { |
263 | 263 | var documentModel = es.DocumentModel.newFromPlainObject( esTest.obj ); |
264 | 264 | |
265 | 265 | // Test 1 |
— | — | @@ -338,6 +338,31 @@ |
339 | 339 | ], |
340 | 340 | 'prepareContentAnnotation works across element boundaries' |
341 | 341 | ); |
| 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 | + ); |
342 | 367 | } ); |
343 | 368 | |
344 | 369 | test( 'es.DocumentModel.prepareRemoval', 11, function() { |
Index: trunk/extensions/VisualEditor/modules/es/models/es.DocumentModel.js |
— | — | @@ -1045,7 +1045,7 @@ |
1046 | 1046 | } |
1047 | 1047 | var i = range.start, |
1048 | 1048 | span = i, |
1049 | | - on = this.data[i].type !== undefined; |
| 1049 | + on = false; |
1050 | 1050 | while ( i < range.end ) { |
1051 | 1051 | if ( this.data[i].type !== undefined ) { |
1052 | 1052 | // Don't annotate structural elements |
— | — | @@ -1059,7 +1059,7 @@ |
1060 | 1060 | } |
1061 | 1061 | } else { |
1062 | 1062 | 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' ) ) { |
1064 | 1064 | // Don't set/clear annotations on content that's already set/cleared |
1065 | 1065 | if ( on ) { |
1066 | 1066 | if ( span ) { |
— | — | @@ -1084,10 +1084,10 @@ |
1085 | 1085 | span++; |
1086 | 1086 | i++; |
1087 | 1087 | } |
| 1088 | + if ( span ) { |
| 1089 | + tx.pushRetain( span ); |
| 1090 | + } |
1088 | 1091 | if ( on ) { |
1089 | | - if ( span ) { |
1090 | | - tx.pushRetain( span ); |
1091 | | - } |
1092 | 1092 | tx.pushStopAnnotating( method, annotation ); |
1093 | 1093 | } |
1094 | 1094 | if ( range.end < this.data.length ) { |