From 329787a07a9fcd8b94f0015ba5ecb0bca3103d88 Mon Sep 17 00:00:00 2001 From: Tobias Andersen Date: Tue, 6 Feb 2018 23:07:41 +0100 Subject: [PATCH] fix(updateSelection): make sure there is a node to extend from (#1603) * fix(updateSelection): make sure there is a node to extend from * fix(updateSelection): use setBaseAndExtent over collapse/extend --- .../slate-react/src/components/content.js | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/slate-react/src/components/content.js b/packages/slate-react/src/components/content.js index b0f5a0df6..ebdb8e460 100644 --- a/packages/slate-react/src/components/content.js +++ b/packages/slate-react/src/components/content.js @@ -207,16 +207,24 @@ class Content extends React.Component { this.tmp.isUpdatingSelection = true native.removeAllRanges() - // COMPAT: IE 11 does not support Selection.extend - if (native.extend) { + // COMPAT: IE 11 does not support Selection.setBaseAndExtent + if (native.setBaseAndExtent) { // COMPAT: Since the DOM range has no concept of backwards/forwards // we need to check and do the right thing here. if (isBackward) { - native.collapse(range.endContainer, range.endOffset) - native.extend(range.startContainer, range.startOffset) + native.setBaseAndExtent( + range.endContainer, + range.endOffset, + range.startContainer, + range.startOffset + ) } else { - native.collapse(range.startContainer, range.startOffset) - native.extend(range.endContainer, range.endOffset) + native.setBaseAndExtent( + range.startContainer, + range.startOffset, + range.endContainer, + range.endOffset + ) } } else { // COMPAT: IE 11 does not support Selection.extend, fallback to addRange