From e8a917f3211eee6f6f7845aa11e9ff92dbfbb4f0 Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Wed, 2 Nov 2011 19:12:31 +1100 Subject: [PATCH] Fix Range#containsNode. Not sufficient for node to be adjacent to range; must actually contain range. --- source/Node.js | 2 -- source/Range.js | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/source/Node.js b/source/Node.js index 40de0eb..c29c0c3 100644 --- a/source/Node.js +++ b/source/Node.js @@ -107,8 +107,6 @@ implement( Text, { getLength: function () { return this.length; }, - // The text node is essentially its own contents. - empty: function () { return this; }, isLike: function ( node ) { return node.nodeType === TEXT_NODE; }, diff --git a/source/Range.js b/source/Range.js index 810cef0..0fdf961 100644 --- a/source/Range.js +++ b/source/Range.js @@ -238,18 +238,18 @@ implement( Range, { // Node must not finish before range starts or start after range // finishes. var nodeEndBeforeStart = ( range.compareBoundaryPoints( - END_TO_START, nodeRange ) === 1 ), + END_TO_START, nodeRange ) > -1 ), nodeStartAfterEnd = ( range.compareBoundaryPoints( - START_TO_END, nodeRange ) === -1 ); + START_TO_END, nodeRange ) < 1 ); return ( !nodeEndBeforeStart && !nodeStartAfterEnd ); } else { // Node must start after range starts and finish before range // finishes var nodeStartAfterStart = ( range.compareBoundaryPoints( - START_TO_START, nodeRange ) === -1 ), + START_TO_START, nodeRange ) < 1 ), nodeEndBeforeEnd = ( range.compareBoundaryPoints( - END_TO_END, nodeRange ) === 1 ); + END_TO_END, nodeRange ) > -1 ); return ( nodeStartAfterStart && nodeEndBeforeEnd ); } },