From 7941b787c2c5340b8915e0ed15483652e9c4f77d Mon Sep 17 00:00:00 2001 From: zhouxinyu Date: Thu, 19 Dec 2024 17:38:28 +0800 Subject: [PATCH] fix: fix issue with remove character --- .../src/plugins/builtin-plugin/edit-module.ts | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/vrender-core/src/plugins/builtin-plugin/edit-module.ts b/packages/vrender-core/src/plugins/builtin-plugin/edit-module.ts index 57762236b..c57f9761e 100644 --- a/packages/vrender-core/src/plugins/builtin-plugin/edit-module.ts +++ b/packages/vrender-core/src/plugins/builtin-plugin/edit-module.ts @@ -246,7 +246,12 @@ export class EditModule { const text = (lastConfig as any).text; const textList: string[] = text ? Array.from(text.toString()) : []; for (let i = 0; i < textList.length; i++) { - textConfig.splice(i + configIdx, 0, { ...lastConfig, isComposing: false, text: textList[i] } as any); + textConfig.splice(i + configIdx, 0, { + fill: 'black', + ...lastConfig, + isComposing: false, + text: textList[i] + } as any); } this.currRt.setAttributes({ textConfig }); const nextConfigIdx = configIdx + textList.length; @@ -304,13 +309,17 @@ export class EditModule { let nextConfigIdx = startIdx; // 删除键 - if (ev.type === 'Backspace' && !this.isComposing && startIdx === endIdx) { - if (startIdx <= 0) { - return; + if (ev.type === 'Backspace' && !this.isComposing) { + if (startIdx === endIdx) { + if (startIdx <= 0) { + return; + } + // 删除 + textConfig.splice(startIdx - 1, 1); + nextConfigIdx = Math.max(startIdx - 1, 0); + } else { + // 不插入内容 } - // 删除 - textConfig.splice(startIdx - 1, 1); - nextConfigIdx = Math.max(startIdx - 1, 0); } else { // 插入 if (!this.isComposing) { @@ -329,7 +338,7 @@ export class EditModule { // nextConfigIdx = Math.min(nextConfigIdx, textConfig.length - 1); let cursorIndex = this.cursorIndex; - if (str.length > 1 && !this.isComposing) { + if (str && str.length > 1 && !this.isComposing) { // 如果字符长度大于1且不是composing,那说明是粘贴 // 拆分 this.parseCompositionStr(nextConfigIdx - 1);