mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-18 13:11:17 +02:00
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
This commit is contained in:
committed by
Ian Storm Taylor
parent
1f254aebec
commit
329787a07a
@@ -207,16 +207,24 @@ class Content extends React.Component {
|
|||||||
this.tmp.isUpdatingSelection = true
|
this.tmp.isUpdatingSelection = true
|
||||||
native.removeAllRanges()
|
native.removeAllRanges()
|
||||||
|
|
||||||
// COMPAT: IE 11 does not support Selection.extend
|
// COMPAT: IE 11 does not support Selection.setBaseAndExtent
|
||||||
if (native.extend) {
|
if (native.setBaseAndExtent) {
|
||||||
// COMPAT: Since the DOM range has no concept of backwards/forwards
|
// COMPAT: Since the DOM range has no concept of backwards/forwards
|
||||||
// we need to check and do the right thing here.
|
// we need to check and do the right thing here.
|
||||||
if (isBackward) {
|
if (isBackward) {
|
||||||
native.collapse(range.endContainer, range.endOffset)
|
native.setBaseAndExtent(
|
||||||
native.extend(range.startContainer, range.startOffset)
|
range.endContainer,
|
||||||
|
range.endOffset,
|
||||||
|
range.startContainer,
|
||||||
|
range.startOffset
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
native.collapse(range.startContainer, range.startOffset)
|
native.setBaseAndExtent(
|
||||||
native.extend(range.endContainer, range.endOffset)
|
range.startContainer,
|
||||||
|
range.startOffset,
|
||||||
|
range.endContainer,
|
||||||
|
range.endOffset
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// COMPAT: IE 11 does not support Selection.extend, fallback to addRange
|
// COMPAT: IE 11 does not support Selection.extend, fallback to addRange
|
||||||
|
Reference in New Issue
Block a user