From 8bc049a0b97da4147f0b064eb743522f198444b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnay=20Mert=20Karado=C4=9Fan?= Date: Thu, 16 Jan 2020 22:16:11 +0000 Subject: [PATCH] Remove resized element if it is invisibly small (#405) --- src/element/index.ts | 1 + src/element/sizeChecks.ts | 5 +++++ src/index.tsx | 14 +++++++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 src/element/sizeChecks.ts diff --git a/src/element/index.ts b/src/element/index.ts index 0e8aac4a..ffcaeb40 100644 --- a/src/element/index.ts +++ b/src/element/index.ts @@ -12,3 +12,4 @@ export { resizeTest } from "./resizeTest"; export { isTextElement } from "./typeChecks"; export { textWysiwyg } from "./textWysiwyg"; export { redrawTextBoundingBox } from "./textElement"; +export { isInvisiblySmallElement } from "./sizeChecks"; diff --git a/src/element/sizeChecks.ts b/src/element/sizeChecks.ts new file mode 100644 index 00000000..01cf9209 --- /dev/null +++ b/src/element/sizeChecks.ts @@ -0,0 +1,5 @@ +import { ExcalidrawElement } from "./types"; + +export function isInvisiblySmallElement(element: ExcalidrawElement): boolean { + return element.width === 0 && element.height === 0; +} diff --git a/src/index.tsx b/src/index.tsx index 05231dd2..f9019315 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -8,6 +8,7 @@ import { newElement, duplicateElement, resizeTest, + isInvisiblySmallElement, isTextElement, textWysiwyg, getElementAbsoluteCoords @@ -978,7 +979,11 @@ export class App extends React.Component<{}, AppState> { }; const onMouseUp = (e: MouseEvent) => { - const { draggingElement, elementType } = this.state; + const { + draggingElement, + resizingElement, + elementType + } = this.state; lastMouseUp = null; window.removeEventListener("mousemove", onMouseMove); @@ -987,8 +992,7 @@ export class App extends React.Component<{}, AppState> { if ( elementType !== "selection" && draggingElement && - draggingElement.width === 0 && - draggingElement.height === 0 + isInvisiblySmallElement(draggingElement) ) { // remove invisible element which was added in onMouseDown elements = elements.slice(0, -1); @@ -999,6 +1003,10 @@ export class App extends React.Component<{}, AppState> { return; } + if (resizingElement && isInvisiblySmallElement(resizingElement)) { + elements = elements.filter(el => el.id !== resizingElement.id); + } + resetCursor(); // If click occured on already selected element