Przeglądaj źródła

Fix #360 prevent creating invisibly small elements (#387)

Günay Mert Karadoğan 5 lat temu
rodzic
commit
4ecc734659
1 zmienionych plików z 15 dodań i 0 usunięć
  1. 15 0
      src/index.tsx

+ 15 - 0
src/index.tsx

@@ -982,6 +982,21 @@ export class App extends React.Component<{}, AppState> {
               window.removeEventListener("mousemove", onMouseMove);
               window.removeEventListener("mouseup", onMouseUp);
 
+              if (
+                elementType !== "selection" &&
+                draggingElement &&
+                draggingElement.width === 0 &&
+                draggingElement.height === 0
+              ) {
+                // remove invisible element which was added in onMouseDown
+                elements = elements.slice(0, -1);
+                this.setState({
+                  draggingElement: null
+                });
+                this.forceUpdate();
+                return;
+              }
+
               resetCursor();
 
               // If click occured on already selected element