mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-12 02:03:59 +02:00
fix getPoint in case of switching between editors, closes #570
This commit is contained in:
@@ -150,11 +150,18 @@ class Content extends React.Component {
|
|||||||
const { state, editor } = this.props
|
const { state, editor } = this.props
|
||||||
const { document } = state
|
const { document } = state
|
||||||
const schema = editor.getSchema()
|
const schema = editor.getSchema()
|
||||||
|
|
||||||
|
// If we can't find an offset key, we can't get a point.
|
||||||
const offsetKey = OffsetKey.findKey(element, offset)
|
const offsetKey = OffsetKey.findKey(element, offset)
|
||||||
if (!offsetKey) return null
|
if (!offsetKey) return null
|
||||||
|
|
||||||
|
// COMPAT: If someone is clicking from one Slate editor into another, the
|
||||||
|
// select event fires two, once for the old editor's `element` first, and
|
||||||
|
// then afterwards for the correct `element`. (2017/03/03)
|
||||||
const { key } = offsetKey
|
const { key } = offsetKey
|
||||||
const node = document.getDescendant(key)
|
const node = document.getDescendant(key)
|
||||||
|
if (!node) return null
|
||||||
|
|
||||||
const decorators = document.getDescendantDecorators(key, schema)
|
const decorators = document.getDescendantDecorators(key, schema)
|
||||||
const ranges = node.getRanges(decorators)
|
const ranges = node.getRanges(decorators)
|
||||||
const point = OffsetKey.findPoint(offsetKey, ranges)
|
const point = OffsetKey.findPoint(offsetKey, ranges)
|
||||||
|
Reference in New Issue
Block a user