fix: boundary error when deleting elements backwards #606

This commit is contained in:
Hufe921
2024-05-27 21:20:29 +08:00
parent af9efec382
commit 500626498f
2 changed files with 2 additions and 1 deletions
+1 -1
View File
@@ -682,7 +682,7 @@ export class Draw {
if (!this.control.getActiveControl()) { if (!this.control.getActiveControl()) {
let deleteIndex = endIndex - 1 let deleteIndex = endIndex - 1
while (deleteIndex >= start) { while (deleteIndex >= start) {
if (elementList[deleteIndex].control?.deletable !== false) { if (elementList[deleteIndex]?.control?.deletable !== false) {
elementList.splice(deleteIndex, 1) elementList.splice(deleteIndex, 1)
} }
deleteIndex-- deleteIndex--
@@ -26,6 +26,7 @@ export function del(evt: KeyboardEvent, host: CanvasEvent) {
if (!isCollapsed) { if (!isCollapsed) {
draw.spliceElementList(elementList, startIndex + 1, endIndex - startIndex) draw.spliceElementList(elementList, startIndex + 1, endIndex - startIndex)
} else { } else {
if (!elementList[index + 1]) return
draw.spliceElementList(elementList, index + 1, 1) draw.spliceElementList(elementList, index + 1, 1)
} }
curIndex = isCollapsed ? index : startIndex curIndex = isCollapsed ? index : startIndex