Browse Source

fix: remove invisible elements safely (#7083)

David Luzar 1 year ago
parent
commit
8b838049df
2 changed files with 6 additions and 2 deletions
  1. 3 1
      src/actions/actionFinalize.tsx
  2. 3 1
      src/components/App.tsx

+ 3 - 1
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,

+ 3 - 1
src/components/App.tsx

@@ -6549,7 +6549,9 @@ class App extends React.Component<AppProps, AppState> {
       ) {
         // 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,