fix:delete error at control boundary
This commit is contained in:
@@ -160,7 +160,7 @@ export class Control {
|
|||||||
}
|
}
|
||||||
} else if (element.controlComponent === ControlComponent.POSTFIX) {
|
} else if (element.controlComponent === ControlComponent.POSTFIX) {
|
||||||
// POSTFIX-移动到最后一个后缀字符后
|
// POSTFIX-移动到最后一个后缀字符后
|
||||||
let startIndex = index + 1
|
let startIndex = newIndex + 1
|
||||||
while (startIndex < elementList.length) {
|
while (startIndex < elementList.length) {
|
||||||
const nextElement = elementList[startIndex]
|
const nextElement = elementList[startIndex]
|
||||||
if (nextElement.controlId !== element.controlId) {
|
if (nextElement.controlId !== element.controlId) {
|
||||||
@@ -173,7 +173,7 @@ export class Control {
|
|||||||
}
|
}
|
||||||
} else if (element.controlComponent === ControlComponent.PREFIX) {
|
} else if (element.controlComponent === ControlComponent.PREFIX) {
|
||||||
// PREFIX-移动到最后一个前缀字符后
|
// PREFIX-移动到最后一个前缀字符后
|
||||||
let startIndex = index + 1
|
let startIndex = newIndex + 1
|
||||||
while (startIndex < elementList.length) {
|
while (startIndex < elementList.length) {
|
||||||
const nextElement = elementList[startIndex]
|
const nextElement = elementList[startIndex]
|
||||||
if (
|
if (
|
||||||
@@ -189,7 +189,7 @@ export class Control {
|
|||||||
}
|
}
|
||||||
} else if (element.controlComponent === ControlComponent.PLACEHOLDER) {
|
} else if (element.controlComponent === ControlComponent.PLACEHOLDER) {
|
||||||
// PLACEHOLDER-移动到第一个前缀后
|
// PLACEHOLDER-移动到第一个前缀后
|
||||||
let startIndex = index - 1
|
let startIndex = newIndex - 1
|
||||||
while (startIndex > 0) {
|
while (startIndex > 0) {
|
||||||
const preElement = elementList[startIndex]
|
const preElement = elementList[startIndex]
|
||||||
if (
|
if (
|
||||||
@@ -235,6 +235,10 @@ export class Control {
|
|||||||
}
|
}
|
||||||
nextIndex++
|
nextIndex++
|
||||||
}
|
}
|
||||||
|
// 控件在最后
|
||||||
|
if (nextIndex === elementList.length) {
|
||||||
|
rightIndex = nextIndex - 1
|
||||||
|
}
|
||||||
if (!~leftIndex || !~rightIndex) return startIndex
|
if (!~leftIndex || !~rightIndex) return startIndex
|
||||||
// 删除元素
|
// 删除元素
|
||||||
elementList.splice(leftIndex + 1, rightIndex - leftIndex)
|
elementList.splice(leftIndex + 1, rightIndex - leftIndex)
|
||||||
|
|||||||
@@ -104,7 +104,8 @@ export class SelectControl implements IControlInstance {
|
|||||||
return this.clearSelect()
|
return this.clearSelect()
|
||||||
} else {
|
} else {
|
||||||
const endNextElement = elementList[endIndex + 1]
|
const endNextElement = elementList[endIndex + 1]
|
||||||
if (startElement.controlComponent === ControlComponent.PREFIX ||
|
if ((startElement.controlComponent === ControlComponent.PREFIX &&
|
||||||
|
endNextElement.controlComponent === ControlComponent.PLACEHOLDER) ||
|
||||||
endNextElement.controlComponent === ControlComponent.POSTFIX ||
|
endNextElement.controlComponent === ControlComponent.POSTFIX ||
|
||||||
startElement.controlComponent === ControlComponent.PLACEHOLDER
|
startElement.controlComponent === ControlComponent.PLACEHOLDER
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -129,7 +129,8 @@ export class TextControl implements IControlInstance {
|
|||||||
return startIndex
|
return startIndex
|
||||||
} else {
|
} else {
|
||||||
const endNextElement = elementList[endIndex + 1]
|
const endNextElement = elementList[endIndex + 1]
|
||||||
if (startElement.controlComponent === ControlComponent.PREFIX ||
|
if ((startElement.controlComponent === ControlComponent.PREFIX &&
|
||||||
|
endNextElement.controlComponent === ControlComponent.PLACEHOLDER) ||
|
||||||
endNextElement.controlComponent === ControlComponent.POSTFIX ||
|
endNextElement.controlComponent === ControlComponent.POSTFIX ||
|
||||||
startElement.controlComponent === ControlComponent.PLACEHOLDER
|
startElement.controlComponent === ControlComponent.PLACEHOLDER
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -270,7 +270,6 @@ export class CanvasEvent {
|
|||||||
const { index } = cursorPosition
|
const { index } = cursorPosition
|
||||||
const { startIndex, endIndex } = this.range.getRange()
|
const { startIndex, endIndex } = this.range.getRange()
|
||||||
const isCollapsed = startIndex === endIndex
|
const isCollapsed = startIndex === endIndex
|
||||||
const element = elementList[index]
|
|
||||||
// 当前激活控件
|
// 当前激活控件
|
||||||
const isPartRangeInControlOutside = this.control.isPartRangeInControlOutside()
|
const isPartRangeInControlOutside = this.control.isPartRangeInControlOutside()
|
||||||
const activeControl = this.control.getActiveControl()
|
const activeControl = this.control.getActiveControl()
|
||||||
@@ -297,8 +296,10 @@ export class CanvasEvent {
|
|||||||
} else if (evt.key === KeyMap.Delete) {
|
} else if (evt.key === KeyMap.Delete) {
|
||||||
if (isReadonly || isPartRangeInControlOutside) return
|
if (isReadonly || isPartRangeInControlOutside) return
|
||||||
let curIndex: number
|
let curIndex: number
|
||||||
if (activeControl && elementList[endIndex + 1]?.controlId === element.controlId) {
|
if (activeControl) {
|
||||||
curIndex = this.control.keydown(evt)
|
curIndex = this.control.keydown(evt)
|
||||||
|
} else if (elementList[endIndex + 1]?.type === ElementType.CONTROL) {
|
||||||
|
curIndex = this.control.removeControl(endIndex + 1)
|
||||||
} else {
|
} else {
|
||||||
if (!isCollapsed) {
|
if (!isCollapsed) {
|
||||||
elementList.splice(startIndex + 1, endIndex - startIndex)
|
elementList.splice(startIndex + 1, endIndex - startIndex)
|
||||||
|
|||||||
Reference in New Issue
Block a user