From 07de7bf596b56676b4d856a081a71c0ba24cfbea Mon Sep 17 00:00:00 2001 From: Samy Pesse Date: Mon, 24 Oct 2016 21:28:30 +0200 Subject: [PATCH] Fix transform moveNodeByKey when container is the parent --- src/transforms/by-key.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/transforms/by-key.js b/src/transforms/by-key.js index 6f339f1ef..6ab368822 100644 --- a/src/transforms/by-key.js +++ b/src/transforms/by-key.js @@ -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() - } + transform = transform.normalizeNodeByKey(parent.key) } return transform