Skip to content

Commit

Permalink
Remove resized element if it is invisibly small (excalidraw#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmertk authored and dwelle committed Jan 16, 2020
1 parent 4234cd8 commit 8bc049a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export { resizeTest } from "./resizeTest";
export { isTextElement } from "./typeChecks";
export { textWysiwyg } from "./textWysiwyg";
export { redrawTextBoundingBox } from "./textElement";
export { isInvisiblySmallElement } from "./sizeChecks";
5 changes: 5 additions & 0 deletions src/element/sizeChecks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ExcalidrawElement } from "./types";

export function isInvisiblySmallElement(element: ExcalidrawElement): boolean {
return element.width === 0 && element.height === 0;
}
14 changes: 11 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
newElement,
duplicateElement,
resizeTest,
isInvisiblySmallElement,
isTextElement,
textWysiwyg,
getElementAbsoluteCoords
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 8bc049a

Please sign in to comment.