From 3c2b1b730b66db9099e48ad3ce5bbcc089f338db Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Fri, 22 Jul 2016 12:37:37 -0700 Subject: [PATCH] fix to not re-render when new selection is inside text nodes --- lib/components/content.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/components/content.js b/lib/components/content.js index 4d997c639..bd6170623 100644 --- a/lib/components/content.js +++ b/lib/components/content.js @@ -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) }