Skip to content

Commit

Permalink
fix: fix issue with remove character
Browse files Browse the repository at this point in the history
  • Loading branch information
neuqzxy committed Dec 23, 2024
1 parent 131ca9f commit 47ad012
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions packages/vrender-core/src/plugins/builtin-plugin/edit-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit 47ad012

Please sign in to comment.