Fixes selecting an element

This commit is contained in:
Giovanni Giordano 2020-01-02 17:38:53 +01:00
parent 70bd7d874f
commit 4a4f36592f

View File

@ -331,10 +331,18 @@ class App extends React.Component {
let isDraggingElements = false; let isDraggingElements = false;
const cursorStyle = document.documentElement.style.cursor; const cursorStyle = document.documentElement.style.cursor;
if (this.state.elementType === "selection") { 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) { if (selectedElement) {
this.setState({ draggingElement: selectedElement }); this.setState({ draggingElement: selectedElement });
} else {
clearSelection()
} }
isDraggingElements = elements.some(element => element.isSelected); isDraggingElements = elements.some(element => element.isSelected);
@ -435,7 +443,6 @@ class App extends React.Component {
isDraggingElements = false; isDraggingElements = false;
} }
elements.pop() elements.pop()
setSelection(draggingElement);
} else { } else {
draggingElement.isSelected = true; draggingElement.isSelected = true;
} }