From 8b838049dfbf6f0aef3e61e51b52e648aa1eba69 Mon Sep 17 00:00:00 2001 From: David Luzar Date: Wed, 4 Oct 2023 16:09:59 +0200 Subject: [PATCH] fix: remove invisible elements safely (#7083) --- src/actions/actionFinalize.tsx | 4 +++- src/components/App.tsx | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/actions/actionFinalize.tsx b/src/actions/actionFinalize.tsx index c25e2ef4..4d422994 100644 --- a/src/actions/actionFinalize.tsx +++ b/src/actions/actionFinalize.tsx @@ -90,7 +90,9 @@ export const actionFinalize = register({ } } if (isInvisiblySmallElement(multiPointElement)) { - newElements = newElements.slice(0, -1); + newElements = newElements.filter( + (el) => el.id !== multiPointElement.id, + ); } // If the multi point line closes the loop, diff --git a/src/components/App.tsx b/src/components/App.tsx index b91e0e4b..2e7c468e 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -6549,7 +6549,9 @@ class App extends React.Component { ) { // remove invisible element which was added in onPointerDown this.scene.replaceAllElements( - this.scene.getElementsIncludingDeleted().slice(0, -1), + this.scene + .getElementsIncludingDeleted() + .filter((el) => el.id !== draggingElement.id), ); this.setState({ draggingElement: null,