1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-19 21:51:51 +02:00

Fix replaceNodeByKey failing to normalize node's parent (#1791)

This commit is contained in:
Gabin Aureche
2018-04-27 22:24:29 +02:00
committed by Ian Storm Taylor
parent 9e50bc6b1f
commit d6245fbadf
2 changed files with 38 additions and 1 deletions

View File

@@ -489,7 +489,7 @@ Changes.replaceNodeByKey = (change, key, newNode, options = {}) => {
const parent = document.getParent(key)
const index = parent.nodes.indexOf(node)
change.removeNodeByKey(key, { normalize: false })
change.insertNodeByKey(parent.key, index, newNode, options)
change.insertNodeByKey(parent.key, index, newNode, { normalize: false })
if (normalize) {
change.normalizeNodeByKey(parent.key)
}

View File

@@ -0,0 +1,37 @@
/** @jsx h */
import h from '../../../helpers/h'
/*
* This test makes sure there are no intermediate normalization
* when calling replaceNodeByKey which calls removeNodeByKey and insertNodeByKey successively.
*/
export default function(change) {
// Replacing <hashtag> by an empty text means the <link> is now empty
// and empty inlines are removed, according to Slate's core schema.
// If an intermediate normalization were to happen, the final normalization
// would fail to find the node's parent and thus throw because that parent
// has already been removed before (due to the intermediate normalization).
change.replaceNodeByKey('a', { object: 'text', text: '' })
}
export const input = (
<value>
<document>
<paragraph>
<link>
<hashtag key="a">lorem</hashtag>
</link>
</paragraph>
</document>
</value>
)
export const output = (
<value>
<document>
<paragraph />
</document>
</value>
)