fix:delete error at control boundary

pr675
Hufe921 4 years ago
parent ba30023842
commit 3418083438

@ -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)

@ -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
) {

@ -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
) {

@ -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)

Loading…
Cancel
Save