mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-25 11:16:51 +00:00
Fix bugs in prepareContentAnnotation() related to structural offsets, and add a test. Also add parenthesis to the if statement mixing || and &&, for clarity
This commit is contained in:
parent
815029f6db
commit
5ac817a6f4
|
@ -1045,7 +1045,7 @@ es.DocumentModel.prototype.prepareContentAnnotation = function( range, method, a
|
|||
}
|
||||
var i = range.start,
|
||||
span = i,
|
||||
on = this.data[i].type !== undefined;
|
||||
on = false;
|
||||
while ( i < range.end ) {
|
||||
if ( this.data[i].type !== undefined ) {
|
||||
// Don't annotate structural elements
|
||||
|
@ -1059,7 +1059,7 @@ es.DocumentModel.prototype.prepareContentAnnotation = function( range, method, a
|
|||
}
|
||||
} else {
|
||||
var covered = es.DocumentModel.getIndexOfAnnotation( this.data[i], annotation ) !== -1;
|
||||
if ( covered && method === 'set' || !covered && method === 'clear' ) {
|
||||
if ( ( covered && method === 'set' ) || ( !covered && method === 'clear' ) ) {
|
||||
// Don't set/clear annotations on content that's already set/cleared
|
||||
if ( on ) {
|
||||
if ( span ) {
|
||||
|
@ -1084,10 +1084,10 @@ es.DocumentModel.prototype.prepareContentAnnotation = function( range, method, a
|
|||
span++;
|
||||
i++;
|
||||
}
|
||||
if ( span ) {
|
||||
tx.pushRetain( span );
|
||||
}
|
||||
if ( on ) {
|
||||
if ( span ) {
|
||||
tx.pushRetain( span );
|
||||
}
|
||||
tx.pushStopAnnotating( method, annotation );
|
||||
}
|
||||
if ( range.end < this.data.length ) {
|
||||
|
|
|
@ -258,7 +258,7 @@ test( 'es.DocumentModel.prepareElementAttributeChange', 4, function() {
|
|||
}
|
||||
} );
|
||||
|
||||
test( 'es.DocumentModel.prepareContentAnnotation', 2, function() {
|
||||
test( 'es.DocumentModel.prepareContentAnnotation', 3, function() {
|
||||
var documentModel = es.DocumentModel.newFromPlainObject( esTest.obj );
|
||||
|
||||
// Test 1
|
||||
|
@ -338,6 +338,31 @@ test( 'es.DocumentModel.prepareContentAnnotation', 2, function() {
|
|||
],
|
||||
'prepareContentAnnotation works across element boundaries'
|
||||
);
|
||||
|
||||
// Test 3
|
||||
deepEqual(
|
||||
documentModel.prepareContentAnnotation(
|
||||
new es.Range( 4, 11 ), 'set', { 'type': 'textStyle/bold' }
|
||||
).getOperations(),
|
||||
[
|
||||
{ 'type': 'retain', 'length': 9 },
|
||||
{
|
||||
'type': 'annotate',
|
||||
'method': 'set',
|
||||
'bias': 'start',
|
||||
'annotation': { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }
|
||||
},
|
||||
{ 'type': 'retain', 'length': 1 },
|
||||
{
|
||||
'type': 'annotate',
|
||||
'method': 'set',
|
||||
'bias': 'stop',
|
||||
'annotation': { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }
|
||||
},
|
||||
{ 'type': 'retain', 'length': 24 }
|
||||
],
|
||||
'prepareContentAnnotation works when given structural offsets'
|
||||
);
|
||||
} );
|
||||
|
||||
test( 'es.DocumentModel.prepareRemoval', 11, function() {
|
||||
|
|
Loading…
Reference in a new issue