diff --git a/packages/designer/src/document/node/node-children.ts b/packages/designer/src/document/node/node-children.ts index 3e0f8814a..527b72c61 100644 --- a/packages/designer/src/document/node/node-children.ts +++ b/packages/designer/src/document/node/node-children.ts @@ -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); + } /** * 删除一个节点 */ diff --git a/packages/designer/src/document/node/node.ts b/packages/designer/src/document/node/node.ts index e480d6b6e..5b11fc097 100644 --- a/packages/designer/src/document/node/node.ts +++ b/packages/designer/src/document/node/node.ts @@ -261,6 +261,15 @@ export class Node { 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 { return comparePosition(this, otherNode); } + unlinkSlot(slotNode: Node) { + const i = this._slots.indexOf(slotNode); + if (i < 0) { + return false; + } + this._slots.splice(i, 1); + } + /** * 删除一个Slot节点 */