Fix nodeSelectionEqual() so it doesn't explode when a and b have unequal lengths

Change-Id: Idb84bc1238576c711a201cdbf05f63a7b603a819
This commit is contained in:
Catrope 2012-05-10 16:42:16 -07:00
parent 9b6402801a
commit 8834145f9e
2 changed files with 28 additions and 2 deletions

View file

@ -168,7 +168,7 @@ ve.Document.prototype.selectNodes = function( range, mode ) {
// node is a leaf node and the range is entirely inside it
return [ {
'node': node,
'range': new ve.Range( left, right ),
'range': new ve.Range( start, end ),
'index': currentFrame.index,
'nodeRange': new ve.Range( left, right )
} ];

View file

@ -129,6 +129,31 @@ ve.example.getSelectNodesCases = function( doc ) {
'nodeRange': new ve.Range( 1, 4 )
}
]
},
{
'actual': doc.selectNodes( new ve.Range( 4, 4 ), 'leaves' ),
'expected': [
// heading/text
{
'node': lookup( documentNode, 0, 0 ),
'range': new ve.Range( 4, 4 ),
'index': 0,
'nodeRange': new ve.Range( 1, 4 )
}
]
},
// Range entirely within one leaf node
{
'actual': doc.selectNodes( new ve.Range( 2, 3 ), 'leaves' ),
'expected': [
// heading/text
{
'node': lookup( documentNode, 0, 0 ),
'range': new ve.Range( 2, 3 ),
'index': 0,
'nodeRange': new ve.Range( 1, 4 )
}
]
}
];
};
@ -161,8 +186,9 @@ ve.example.nodeTreeEqual = function( a, b ) {
* @method
*/
ve.example.nodeSelectionEqual = function( a, b ) {
var minLength = a.length < b.length ? a.length : b.length;
equal( a.length, b.length, 'length match' );
for ( var i = 0; i < a.length; i++ ) {
for ( var i = 0; i < minLength; i++ ) {
ok( a[i].node === b[i].node, 'node match' );
if ( a[i].range && b[i].range ) {
deepEqual( a[i].range, b[i].range, 'range match' );