fix: 拖拽时要解除与原来节点的关系

This commit is contained in:
力皓 2020-09-07 14:19:09 +08:00
parent 2bcd87741e
commit 7a6bf2cdb4
2 changed files with 24 additions and 0 deletions

View File

@ -106,6 +106,13 @@ export class NodeChildren {
});
}
unlinkChild(node: Node) {
const i = this.children.indexOf(node);
if (i < 0) {
return false;
}
this.children.splice(i, 1);
}
/**
*
*/

View File

@ -261,6 +261,15 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
return;
}
// 解除老的父子关系,但不需要真的删除节点
if (this._parent) {
if (this.isSlot()) {
this._parent.unlinkSlot(this);
} else {
this._parent.children.unlinkChild(this);
}
}
// 建立新的父子关系
this._parent = parent;
if (parent) {
this.document.removeWillPurge(this);
@ -640,6 +649,14 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
return comparePosition(this, otherNode);
}
unlinkSlot(slotNode: Node) {
const i = this._slots.indexOf(slotNode);
if (i < 0) {
return false;
}
this._slots.splice(i, 1);
}
/**
* Slot节点
*/