Skip to content

Commit

Permalink
Prevent 'Invalid argument' error when triple-clicking to select on IE
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoran Brondsema committed May 12, 2016
1 parent 99e6d76 commit 6c41499
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/js/utils/selection-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,21 @@ function comparePosition(selection) {
// made.
//
if (position & Node.DOCUMENT_POSITION_CONTAINS) {
if (focusOffset < focusNode.childNodes.length) {
focusNode = focusNode.childNodes[focusOffset];
focusOffset = 0;
} else {
// This situation happens on IE when triple-clicking to select.
// Set the focus to the very last character inside the node.
while (focusNode.lastChild) {
focusNode = focusNode.lastChild;
}
focusOffset = focusNode.textContent.length;
}

return comparePosition({
focusNode: focusNode.childNodes[focusOffset],
focusOffset: 0,
focusNode,
focusOffset,
anchorNode, anchorOffset
});
} else if (position & Node.DOCUMENT_POSITION_CONTAINED_BY) {
Expand Down

0 comments on commit 6c41499

Please sign in to comment.