Better selection click detection (#50)
This commit is contained in:
parent
8a43ed691d
commit
278fc11d22
@ -530,21 +530,26 @@ class App extends React.Component<{}, AppState> {
|
|||||||
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(element => {
|
const hitElement = elements.find(element => {
|
||||||
const isSelected = hitTest(element, x, y);
|
return hitTest(element, x, y);
|
||||||
if (isSelected) {
|
|
||||||
element.isSelected = true;
|
|
||||||
}
|
|
||||||
return isSelected;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// deselect everything except target element to-be-selected
|
// If we click on something
|
||||||
elements.forEach(element => {
|
if (hitElement) {
|
||||||
if (element === selectedElement) return;
|
if (hitElement.isSelected) {
|
||||||
element.isSelected = false;
|
// If that element is not already selected, do nothing,
|
||||||
});
|
// we're likely going to drag it
|
||||||
if (selectedElement) {
|
} else {
|
||||||
this.setState({ draggingElement: selectedElement });
|
// We unselect every other elements unless shift is pressed
|
||||||
|
if (!e.shiftKey) {
|
||||||
|
clearSelection();
|
||||||
|
}
|
||||||
|
// No matter what, we select it
|
||||||
|
hitElement.isSelected = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// If we don't click on anything, let's remove all the selected elements
|
||||||
|
clearSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
isDraggingElements = elements.some(
|
isDraggingElements = elements.some(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user