Skip to content

Commit b40f6be

Browse files
authored
fix: correctly handle delete action (#3)
fix: correctly handle delete action
2 parents 29acaf1 + 02d5490 commit b40f6be

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/ReactPictureAnnotation.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,11 @@ export default class ReactPictureAnnotation extends React.Component<
273273
};
274274

275275
private onDelete = () => {
276-
if (
277-
this.shapes.length > 0 &&
278-
this.shapes[this.shapes.length - 1].getAnnotationData().id ===
279-
this.selectedId
280-
) {
281-
this.shapes.pop();
276+
const deleteTarget = this.shapes.findIndex(
277+
shape => shape.getAnnotationData().id === this.selectedId
278+
);
279+
if (deleteTarget >= 0) {
280+
this.shapes.splice(deleteTarget, 1);
282281
this.onShapeChange();
283282
}
284283
};

0 commit comments

Comments
 (0)