Remove resized element if it is invisibly small (#405)

This commit is contained in:
Günay Mert Karadoğan 2020-01-16 22:16:11 +00:00 committed by David Luzar
parent 4234cd849c
commit 8bc049a0b9
3 changed files with 17 additions and 3 deletions

View File

@ -12,3 +12,4 @@ export { resizeTest } from "./resizeTest";
export { isTextElement } from "./typeChecks"; export { isTextElement } from "./typeChecks";
export { textWysiwyg } from "./textWysiwyg"; export { textWysiwyg } from "./textWysiwyg";
export { redrawTextBoundingBox } from "./textElement"; export { redrawTextBoundingBox } from "./textElement";
export { isInvisiblySmallElement } from "./sizeChecks";

View File

@ -0,0 +1,5 @@
import { ExcalidrawElement } from "./types";
export function isInvisiblySmallElement(element: ExcalidrawElement): boolean {
return element.width === 0 && element.height === 0;
}

View File

@ -8,6 +8,7 @@ import {
newElement, newElement,
duplicateElement, duplicateElement,
resizeTest, resizeTest,
isInvisiblySmallElement,
isTextElement, isTextElement,
textWysiwyg, textWysiwyg,
getElementAbsoluteCoords getElementAbsoluteCoords
@ -978,7 +979,11 @@ export class App extends React.Component<{}, AppState> {
}; };
const onMouseUp = (e: MouseEvent) => { const onMouseUp = (e: MouseEvent) => {
const { draggingElement, elementType } = this.state; const {
draggingElement,
resizingElement,
elementType
} = this.state;
lastMouseUp = null; lastMouseUp = null;
window.removeEventListener("mousemove", onMouseMove); window.removeEventListener("mousemove", onMouseMove);
@ -987,8 +992,7 @@ export class App extends React.Component<{}, AppState> {
if ( if (
elementType !== "selection" && elementType !== "selection" &&
draggingElement && draggingElement &&
draggingElement.width === 0 && isInvisiblySmallElement(draggingElement)
draggingElement.height === 0
) { ) {
// remove invisible element which was added in onMouseDown // remove invisible element which was added in onMouseDown
elements = elements.slice(0, -1); elements = elements.slice(0, -1);
@ -999,6 +1003,10 @@ export class App extends React.Component<{}, AppState> {
return; return;
} }
if (resizingElement && isInvisiblySmallElement(resizingElement)) {
elements = elements.filter(el => el.id !== resizingElement.id);
}
resetCursor(); resetCursor();
// If click occured on already selected element // If click occured on already selected element