1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-26 08:34:28 +02:00

fix to not re-render when new selection is inside text nodes

This commit is contained in:
Ian Storm Taylor
2016-07-22 12:37:37 -07:00
parent e8fdacd340
commit 3c2b1b730b

View File

@@ -378,10 +378,18 @@ class Content extends React.Component {
return return
} }
// Calculate the Slate-specific selection based on the native one.
const { anchorNode, anchorOffset, focusNode, focusOffset } = native const { anchorNode, anchorOffset, focusNode, focusOffset } = native
const anchor = OffsetKey.findPoint(anchorNode, anchorOffset, state) const anchor = OffsetKey.findPoint(anchorNode, anchorOffset, state)
const focus = OffsetKey.findPoint(focusNode, focusOffset, state) const focus = OffsetKey.findPoint(focusNode, focusOffset, state)
// If the native selection is inside text nodes, we can trust the native
// state and not need to re-render.
const isNative = (
anchorNode.nodeType == 3 &&
focusNode.nodeType == 3
)
state = state state = state
.transform() .transform()
.focus() .focus()
@@ -391,7 +399,7 @@ class Content extends React.Component {
focusKey: focus.key, focusKey: focus.key,
focusOffset: focus.offset focusOffset: focus.offset
}) })
.apply() .apply({ isNative })
this.onChange(state) this.onChange(state)
} }