From 46d5d9ab3ad2ff06fa47365ed2e3469d2306c0e0 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Sat, 10 Sep 2016 18:30:57 -0700 Subject: [PATCH] fix re-render logic for leaf nodes on blur/focus --- lib/components/leaf.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/components/leaf.js b/lib/components/leaf.js index c96002ed1..4b8131304 100644 --- a/lib/components/leaf.js +++ b/lib/components/leaf.js @@ -95,15 +95,24 @@ class Leaf extends React.Component { const text = this.renderText(props) if (el.textContent != text) return true - // Otherwise, there aren't any content changes in this leaf, so if the - // selection is blurred we don't need to render to update it. - if (props.state.isBlurred) return false + // If the selection was previously focused, and now it isn't, re-render so + // that the selection will be properly removed. + if (this.props.state.isFocused && props.state.isBlurred) { + const { index, node, ranges, state } = this.props + const { start, end } = OffsetKey.findBounds(index, ranges) + if (state.selection.hasEdgeBetween(node, start, end)) return true + } - // Otherwise, if it's focused, only re-render if this leaf contains one or - // both of the selection's edges. - const { index, node, state } = props - const { start, end } = OffsetKey.findBounds(index, props.ranges) - return state.selection.hasEdgeBetween(node, start, end) + // If the selection will be focused, only re-render if this leaf contains + // one or both of the selection's edges. + if (props.state.isFocused) { + const { index, node, ranges, state } = props + const { start, end } = OffsetKey.findBounds(index, ranges) + if (state.selection.hasEdgeBetween(node, start, end)) return true + } + + // Otherwise, don't update. + return false } /**