1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-23 15:32:59 +02:00

Preserve node reference when splitting

This commit is contained in:
Samy Pessé
2016-10-31 10:43:27 +01:00
parent 6d88672e83
commit d6e7fb6bf0

View File

@@ -1219,7 +1219,12 @@ const Node = {
else { else {
const { nodes } = child const { nodes } = child
const oneNodes = nodes.takeUntil(n => n.key == one.key).push(one)
// Try to preserve the nodes list to preserve reference of one == node to avoid re-render
// When spliting at the end of a text node, the first node is preserved
let oneNodes = nodes.takeUntil(n => n.key == one.key)
oneNodes = (oneNodes.size == (nodes.size - 1) && one == nodes.last()) ? nodes : oneNodes.push(one)
const twoNodes = nodes.skipUntil(n => n.key == one.key).rest().unshift(two) const twoNodes = nodes.skipUntil(n => n.key == one.key).rest().unshift(two)
one = child.merge({ nodes: oneNodes }) one = child.merge({ nodes: oneNodes })
two = child.merge({ nodes: twoNodes, key: uid() }) two = child.merge({ nodes: twoNodes, key: uid() })