From 380b368986219041d23b2a11dc60d24f83fa01be Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Mon, 19 Aug 2013 20:48:13 +0100 Subject: [PATCH] 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 --- .../dm/lineardata/ve.dm.ElementLinearData.js | 8 +++---- .../ve.dm.ElementLinearData.test.js | 22 +++++++++++++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/modules/ve/dm/lineardata/ve.dm.ElementLinearData.js b/modules/ve/dm/lineardata/ve.dm.ElementLinearData.js index 688d9e5b52..91ff5fba54 100644 --- a/modules/ve/dm/lineardata/ve.dm.ElementLinearData.js +++ b/modules/ve/dm/lineardata/ve.dm.ElementLinearData.js @@ -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 diff --git a/modules/ve/test/dm/lineardata/ve.dm.ElementLinearData.test.js b/modules/ve/test/dm/lineardata/ve.dm.ElementLinearData.test.js index b82808fe19..4d0498eed9 100644 --- a/modules/ve/test/dm/lineardata/ve.dm.ElementLinearData.test.js +++ b/modules/ve/test/dm/lineardata/ve.dm.ElementLinearData.test.js @@ -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 ); }