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:
@@ -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 {Transform} transform
|
||||||
* @param {String} key
|
* @param {String} key
|
||||||
@@ -133,16 +134,12 @@ export function moveNodeByKey(transform, key, newKey, newIndex, options = {}) {
|
|||||||
const { document } = state
|
const { document } = state
|
||||||
const path = document.getPath(key)
|
const path = document.getPath(key)
|
||||||
const newPath = document.getPath(newKey)
|
const newPath = document.getPath(newKey)
|
||||||
|
const parent = document.key == newKey ? null : document.getCommonAncestor(key, newKey)
|
||||||
|
|
||||||
transform = transform.moveNodeOperation(path, newPath, newIndex)
|
transform = transform.moveNodeOperation(path, newPath, newIndex)
|
||||||
const parent = document.getCommonAncestor(key, newKey)
|
|
||||||
|
|
||||||
if (normalize) {
|
if (normalize) {
|
||||||
if (parent) {
|
transform = transform.normalizeNodeByKey(parent.key)
|
||||||
transform = transform.normalizeNodeByKey(parent.key)
|
|
||||||
} else {
|
|
||||||
transform = transform.normalizeDocument()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
return transform
|
||||||
|
Reference in New Issue
Block a user