diff --git a/src/editor/core/draw/control/Control.ts b/src/editor/core/draw/control/Control.ts index 291855e..e71e951 100644 --- a/src/editor/core/draw/control/Control.ts +++ b/src/editor/core/draw/control/Control.ts @@ -160,7 +160,7 @@ export class Control { } } else if (element.controlComponent === ControlComponent.POSTFIX) { // POSTFIX-移动到最后一个后缀字符后 - let startIndex = index + 1 + let startIndex = newIndex + 1 while (startIndex < elementList.length) { const nextElement = elementList[startIndex] if (nextElement.controlId !== element.controlId) { @@ -173,7 +173,7 @@ export class Control { } } else if (element.controlComponent === ControlComponent.PREFIX) { // PREFIX-移动到最后一个前缀字符后 - let startIndex = index + 1 + let startIndex = newIndex + 1 while (startIndex < elementList.length) { const nextElement = elementList[startIndex] if ( @@ -189,7 +189,7 @@ export class Control { } } else if (element.controlComponent === ControlComponent.PLACEHOLDER) { // PLACEHOLDER-移动到第一个前缀后 - let startIndex = index - 1 + let startIndex = newIndex - 1 while (startIndex > 0) { const preElement = elementList[startIndex] if ( @@ -235,6 +235,10 @@ export class Control { } nextIndex++ } + // 控件在最后 + if (nextIndex === elementList.length) { + rightIndex = nextIndex - 1 + } if (!~leftIndex || !~rightIndex) return startIndex // 删除元素 elementList.splice(leftIndex + 1, rightIndex - leftIndex) diff --git a/src/editor/core/draw/control/select/SelectControl.ts b/src/editor/core/draw/control/select/SelectControl.ts index 9677995..10b44a5 100644 --- a/src/editor/core/draw/control/select/SelectControl.ts +++ b/src/editor/core/draw/control/select/SelectControl.ts @@ -104,7 +104,8 @@ export class SelectControl implements IControlInstance { return this.clearSelect() } else { const endNextElement = elementList[endIndex + 1] - if (startElement.controlComponent === ControlComponent.PREFIX || + if ((startElement.controlComponent === ControlComponent.PREFIX && + endNextElement.controlComponent === ControlComponent.PLACEHOLDER) || endNextElement.controlComponent === ControlComponent.POSTFIX || startElement.controlComponent === ControlComponent.PLACEHOLDER ) { diff --git a/src/editor/core/draw/control/text/TextControl.ts b/src/editor/core/draw/control/text/TextControl.ts index 3d5521e..dccf8e7 100644 --- a/src/editor/core/draw/control/text/TextControl.ts +++ b/src/editor/core/draw/control/text/TextControl.ts @@ -129,7 +129,8 @@ export class TextControl implements IControlInstance { return startIndex } else { const endNextElement = elementList[endIndex + 1] - if (startElement.controlComponent === ControlComponent.PREFIX || + if ((startElement.controlComponent === ControlComponent.PREFIX && + endNextElement.controlComponent === ControlComponent.PLACEHOLDER) || endNextElement.controlComponent === ControlComponent.POSTFIX || startElement.controlComponent === ControlComponent.PLACEHOLDER ) { diff --git a/src/editor/core/event/CanvasEvent.ts b/src/editor/core/event/CanvasEvent.ts index a413a02..49ec119 100644 --- a/src/editor/core/event/CanvasEvent.ts +++ b/src/editor/core/event/CanvasEvent.ts @@ -270,7 +270,6 @@ export class CanvasEvent { const { index } = cursorPosition const { startIndex, endIndex } = this.range.getRange() const isCollapsed = startIndex === endIndex - const element = elementList[index] // 当前激活控件 const isPartRangeInControlOutside = this.control.isPartRangeInControlOutside() const activeControl = this.control.getActiveControl() @@ -297,8 +296,10 @@ export class CanvasEvent { } else if (evt.key === KeyMap.Delete) { if (isReadonly || isPartRangeInControlOutside) return let curIndex: number - if (activeControl && elementList[endIndex + 1]?.controlId === element.controlId) { + if (activeControl) { curIndex = this.control.keydown(evt) + } else if (elementList[endIndex + 1]?.type === ElementType.CONTROL) { + curIndex = this.control.removeControl(endIndex + 1) } else { if (!isCollapsed) { elementList.splice(startIndex + 1, endIndex - startIndex)