From 23269625e12bb853392f2a140a6a9b4999d57c46 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Wed, 27 Dec 2023 19:57:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(editor):=20=E4=B8=8A=E4=B8=8B=E7=A7=BB?= =?UTF-8?q?=E4=B8=80=E5=B1=82=E6=BA=A2=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #563 --- packages/editor/src/services/editor.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/editor/src/services/editor.ts b/packages/editor/src/services/editor.ts index 60b85d87..f68004c1 100644 --- a/packages/editor/src/services/editor.ts +++ b/packages/editor/src/services/editor.ts @@ -775,17 +775,23 @@ class Editor extends BaseService { const layout = await this.getLayout(parent, node); const isRelative = layout === Layout.RELATIVE; - brothers.splice(index, 1); - + let offsetIndex: number; if (offset === LayerOffset.TOP) { - brothers.splice(isRelative ? 0 : brothers.length, 0, node); + offsetIndex = isRelative ? 0 : brothers.length; } else if (offset === LayerOffset.BOTTOM) { - brothers.splice(isRelative ? brothers.length : 0, 0, node); + offsetIndex = isRelative ? brothers.length : 0; } else { - brothers.splice(index + (isRelative ? -offset : offset), 0, node); + offsetIndex = index + (isRelative ? -offset : offset); } + if ((offsetIndex > 0 && offsetIndex > brothers.length) || offsetIndex < 0) { + return; + } + brothers.splice(index, 1); + brothers.splice(offsetIndex, 0, node); + const grandparent = this.getParentById(parent.id); + this.get('stage')?.update({ config: cloneDeep(toRaw(parent)), parentId: grandparent?.id, @@ -794,6 +800,8 @@ class Editor extends BaseService { this.addModifiedNodeId(parent.id); this.pushHistoryState(); + + this.emit('move-layer', offset); } /**