1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-21 23:53:50 +01: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
}
// Calculate the Slate-specific selection based on the native one.
const { anchorNode, anchorOffset, focusNode, focusOffset } = native
const anchor = OffsetKey.findPoint(anchorNode, anchorOffset, 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
.transform()
.focus()
@ -391,7 +399,7 @@ class Content extends React.Component {
focusKey: focus.key,
focusOffset: focus.offset
})
.apply()
.apply({ isNative })
this.onChange(state)
}