From aeefca34caa86f9f52fb742e3f7555cd0364baa4 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Wed, 1 Nov 2023 20:46:53 +0800 Subject: [PATCH] fix: clone payload data when call add element api #308 --- src/editor/core/command/CommandAdapt.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index 56f9781..b65bafd 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -1920,11 +1920,12 @@ export class CommandAdapt { if (!payload.length) return const isReadonly = this.draw.isReadonly() if (isReadonly) return + const cloneElementList = deepClone(payload) // 格式化上下文信息 const { startIndex } = this.range.getRange() const elementList = this.draw.getElementList() - formatElementContext(elementList, payload, startIndex) - this.draw.insertElementList(payload) + formatElementContext(elementList, cloneElementList, startIndex) + this.draw.insertElementList(cloneElementList) } public appendElementList( @@ -1934,7 +1935,7 @@ export class CommandAdapt { if (!elementList.length) return const isReadonly = this.draw.isReadonly() if (isReadonly) return - this.draw.appendElementList(elementList, options) + this.draw.appendElementList(deepClone(elementList), options) } public setValue(payload: Partial) {