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

Fix transform moveNodeByKey when container is the parent

This commit is contained in:
Samy Pesse
2016-10-24 21:28:30 +02:00
parent ddf2221929
commit 07de7bf596

View File

@@ -116,7 +116,8 @@ export function joinNodeByKey(transform, key, withKey, options = {}) {
}
/**
* Move a node by `key` to a new parent by `key` and `index`.
* Move a node by `key` to a new parent by `newKey` and `index`.
* `newKey` is the key of the container (it can be the document itself)
*
* @param {Transform} transform
* @param {String} key
@@ -133,16 +134,12 @@ export function moveNodeByKey(transform, key, newKey, newIndex, options = {}) {
const { document } = state
const path = document.getPath(key)
const newPath = document.getPath(newKey)
const parent = document.key == newKey ? null : document.getCommonAncestor(key, newKey)
transform = transform.moveNodeOperation(path, newPath, newIndex)
const parent = document.getCommonAncestor(key, newKey)
if (normalize) {
if (parent) {
transform = transform.normalizeNodeByKey(parent.key)
} else {
transform = transform.normalizeDocument()
}
}
return transform