mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-02 03:32:36 +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)
|
const text = this.renderText(props)
|
||||||
if (el.textContent != text) return true
|
if (el.textContent != text) return true
|
||||||
|
|
||||||
// Otherwise, there aren't any content changes in this leaf, so if the
|
// If the selection was previously focused, and now it isn't, re-render so
|
||||||
// selection is blurred we don't need to render to update it.
|
// that the selection will be properly removed.
|
||||||
if (props.state.isBlurred) return false
|
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
|
// If the selection will be focused, only re-render if this leaf contains
|
||||||
// both of the selection's edges.
|
// one or both of the selection's edges.
|
||||||
const { index, node, state } = props
|
if (props.state.isFocused) {
|
||||||
const { start, end } = OffsetKey.findBounds(index, props.ranges)
|
const { index, node, ranges, state } = props
|
||||||
return state.selection.hasEdgeBetween(node, start, end)
|
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