mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-27 17:09:53 +02:00
fix re-rendering of last text nodes, closes #682
This commit is contained in:
@@ -109,7 +109,7 @@ class Node extends React.Component {
|
||||
// If the node is a block or inline, which can have custom renderers, we
|
||||
// include an extra check to re-render if the node's focus changes, to make
|
||||
// it simple for users to show a node's "selected" state.
|
||||
if (props.node.kind != 'text') {
|
||||
if (nextProps.node.kind != 'text') {
|
||||
const hasEdgeIn = props.state.selection.hasEdgeIn(props.node)
|
||||
const nextHasEdgeIn = nextProps.state.selection.hasEdgeIn(nextProps.node)
|
||||
const hasFocus = props.state.isFocused || nextProps.state.isFocused
|
||||
@@ -127,6 +127,14 @@ class Node extends React.Component {
|
||||
if (!nextRanges.equals(ranges)) return true
|
||||
}
|
||||
|
||||
// If the node is a text node, and its parent is a block node, and it was
|
||||
// the last child of the block, re-render to cleanup extra `<br/>` or `\n`.
|
||||
if (nextProps.node.kind == 'text' && nextProps.parent.kind == 'block') {
|
||||
const last = props.parent.nodes.last()
|
||||
const nextLast = nextProps.parent.nodes.last()
|
||||
if (props.node == last && nextProps.node != nextLast) return true
|
||||
}
|
||||
|
||||
// Otherwise, don't update.
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user