Merge pull request #37 from vjeux/select-on-click
Fixes selecting an element
This commit is contained in:
commit
e260904244
13
src/index.js
13
src/index.js
@ -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);
|
||||||
@ -424,7 +432,7 @@ class App extends React.Component {
|
|||||||
document.documentElement.style.cursor = cursorStyle;
|
document.documentElement.style.cursor = cursorStyle;
|
||||||
|
|
||||||
// if no element is clicked, clear the selection and redraw
|
// if no element is clicked, clear the selection and redraw
|
||||||
if (draggingElement === null) {
|
if (draggingElement === null ) {
|
||||||
clearSelection()
|
clearSelection()
|
||||||
drawScene();
|
drawScene();
|
||||||
return
|
return
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user