mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-29 09:59:48 +02:00
removed ie/edge condition that causes "node of undefined" TypeError if editor is empty (#2689)
This commit is contained in:
committed by
Ian Storm Taylor
parent
8b27e7e184
commit
7855783b2d
@@ -1,10 +1,8 @@
|
|||||||
import getWindow from 'get-window'
|
import getWindow from 'get-window'
|
||||||
import invariant from 'tiny-invariant'
|
import invariant from 'tiny-invariant'
|
||||||
import { IS_IE, IS_EDGE } from 'slate-dev-environment'
|
|
||||||
import { Value } from 'slate'
|
import { Value } from 'slate'
|
||||||
|
|
||||||
import findPoint from './find-point'
|
import findPoint from './find-point'
|
||||||
import findDOMPoint from './find-dom-point'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a Slate range from a DOM `native` selection.
|
* Find a Slate range from a DOM `native` selection.
|
||||||
@@ -51,21 +49,6 @@ function findRange(native, editor) {
|
|||||||
const focus = isCollapsed ? anchor : findPoint(focusNode, focusOffset, editor)
|
const focus = isCollapsed ? anchor : findPoint(focusNode, focusOffset, editor)
|
||||||
if (!anchor || !focus) return null
|
if (!anchor || !focus) return null
|
||||||
|
|
||||||
// COMPAT: ??? The Edge browser seems to have a case where if you select the
|
|
||||||
// last word of a span, it sets the endContainer to the containing span.
|
|
||||||
// `selection-is-backward` doesn't handle this case.
|
|
||||||
if (IS_IE || IS_EDGE) {
|
|
||||||
const domAnchor = findDOMPoint(anchor)
|
|
||||||
const domFocus = findDOMPoint(focus)
|
|
||||||
|
|
||||||
native = {
|
|
||||||
anchorNode: domAnchor.node,
|
|
||||||
anchorOffset: domAnchor.offset,
|
|
||||||
focusNode: domFocus.node,
|
|
||||||
focusOffset: domFocus.offset,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const { document } = value
|
const { document } = value
|
||||||
const range = document.createRange({
|
const range = document.createRange({
|
||||||
anchor,
|
anchor,
|
||||||
|
Reference in New Issue
Block a user