From 7a6bf2cdb4a2d7dccae36874c72012835fce4d52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Mon, 7 Sep 2020 14:19:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8B=96=E6=8B=BD=E6=97=B6=E8=A6=81?= =?UTF-8?q?=E8=A7=A3=E9=99=A4=E4=B8=8E=E5=8E=9F=E6=9D=A5=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E7=9A=84=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designer/src/document/node/node-children.ts | 7 +++++++ packages/designer/src/document/node/node.ts | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) 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节点 */