getAnnotationsFromRange should only ignore non-content data

Currently ignores all non-element data, but element content (e.g.
images) can be annotated.

Added test cases and updated the test runner to only compare
store indexes for a more readable output.

Bug: 50127
Change-Id: I234586a28072811c8288aab56f6abaaa0da0c88d
This commit is contained in:
Ed Sanders 2013-08-19 20:48:13 +01:00
parent 1987d3aa2b
commit 380b368986
2 changed files with 23 additions and 7 deletions

View file

@ -433,9 +433,7 @@ ve.dm.ElementLinearData.prototype.getAnnotatedRangeFromSelection = function ( ra
* @returns {ve.dm.AnnotationSet} All annotation objects range is covered by
*/
ve.dm.ElementLinearData.prototype.getAnnotationsFromRange = function ( range, all ) {
var i,
left,
right;
var i, left, right;
// Look at left side of range for annotations
left = this.getAnnotationsFromOffset( range.start );
// Shortcut for single character and zero-length ranges
@ -444,8 +442,8 @@ ve.dm.ElementLinearData.prototype.getAnnotationsFromRange = function ( range, al
}
// Iterator over the range, looking for annotations, starting at the 2nd character
for ( i = range.start + 1; i < range.end; i++ ) {
// Skip non character data
if ( this.isElementData( i ) ) {
// Skip non-content data
if ( this.isElementData( i ) && !ve.dm.nodeFactory.isNodeContent( this.getType( i ) ) ) {
continue;
}
// Current character annotations

View file

@ -214,6 +214,24 @@ QUnit.test( 'getAnnotationsFromRange', 1, function ( assert ) {
],
'expected': []
},
{
'msg': 'no common coverage due to un-annotated content node',
'data': [
['a', [ { 'type': 'textStyle/bold' } ] ],
{ 'type': 'image' },
{ 'type': '/image' }
],
'expected': []
},
{
'msg': 'branch node is ignored',
'data': [
['a', [ { 'type': 'textStyle/bold' } ] ],
{ 'type': 'paragraph' },
{ 'type': '/paragraph' }
],
'expected': [ { 'type': 'textStyle/bold' } ]
},
{
'msg': 'annotations are collected using all with mismatched annotations',
'data': [
@ -284,8 +302,8 @@ QUnit.test( 'getAnnotationsFromRange', 1, function ( assert ) {
data = ve.dm.example.preprocessAnnotations( cases[i].data );
doc = new ve.dm.Document( data );
assert.deepEqual(
doc.data.getAnnotationsFromRange( new ve.Range( 0, cases[i].data.length ), cases[i].all ),
ve.dm.example.createAnnotationSet( doc.getStore(), cases[i].expected ),
doc.data.getAnnotationsFromRange( new ve.Range( 0, cases[i].data.length ), cases[i].all ).getIndexes(),
ve.dm.example.createAnnotationSet( doc.getStore(), cases[i].expected ).getIndexes(),
cases[i].msg
);
}