diff --git a/modules/ve2/ve.Document.js b/modules/ve2/ve.Document.js index 026fd52410..f9664adb0a 100644 --- a/modules/ve2/ve.Document.js +++ b/modules/ve2/ve.Document.js @@ -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 ) } ]; diff --git a/tests/ve2/ve.example.js b/tests/ve2/ve.example.js index d29ddbb944..5a6fa1cb76 100644 --- a/tests/ve2/ve.example.js +++ b/tests/ve2/ve.example.js @@ -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' );