From 4a4f36592fa7972845587e285e84b946419147c7 Mon Sep 17 00:00:00 2001 From: Giovanni Giordano Date: Thu, 2 Jan 2020 17:38:53 +0100 Subject: [PATCH] Fixes selecting an element --- src/index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 89c34d8f..51a91ba1 100644 --- a/src/index.js +++ b/src/index.js @@ -331,10 +331,18 @@ class App extends React.Component { let isDraggingElements = false; const cursorStyle = document.documentElement.style.cursor; if (this.state.elementType === "selection") { - const selectedElement = elements.find(isInsideAnElement(x, y)) + const selectedElement = elements.find(element => { + const isSelected = isInsideAnElement(x, y)(element) + if (isSelected) { + element.isSelected = true + } + return isSelected + }) if (selectedElement) { this.setState({ draggingElement: selectedElement }); + } else { + clearSelection() } isDraggingElements = elements.some(element => element.isSelected); @@ -424,7 +432,7 @@ class App extends React.Component { document.documentElement.style.cursor = cursorStyle; // if no element is clicked, clear the selection and redraw - if (draggingElement === null) { + if (draggingElement === null ) { clearSelection() drawScene(); return @@ -435,7 +443,6 @@ class App extends React.Component { isDraggingElements = false; } elements.pop() - setSelection(draggingElement); } else { draggingElement.isSelected = true; }