mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-31 19:01:54 +02:00
fix re-render logic for leaf nodes on blur/focus
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user