From 291ea26b06c39b6649dbc6fff2fdb75748756556 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Tue, 26 Mar 2024 21:29:36 +0800 Subject: [PATCH] fix: cannot deletable elements boundary error #491 --- src/editor/core/draw/Draw.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index 81c339a..613f447 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -656,8 +656,23 @@ export class Draw { startIndex++ } } + // 元素删除(不可删除控件忽略) + if (!this.control.getActiveControl()) { + let deleteIndex = endIndex - 1 + while (deleteIndex >= start) { + if (elementList[deleteIndex].control?.deletable !== false) { + elementList.splice(deleteIndex, 1) + } + deleteIndex-- + } + } else { + elementList.splice(start, deleteCount) + } + } + // 循环添加,避免使用解构影响性能 + for (let i = 0; i < items.length; i++) { + elementList.splice(start + i, 0, items[i]) } - elementList.splice(start, deleteCount, ...items) } public getCanvasEvent(): CanvasEvent {