mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Allow deselecting items with SHIFT key
- Refactor hit detection code
This commit is contained in:
parent
75e0a31d3c
commit
1b9572fcc0
1 changed files with 10 additions and 13 deletions
|
@ -775,21 +775,21 @@ export class App extends React.Component<{}, AppState> {
|
||||||
document.documentElement.style.cursor = `${resizeHandle}-resize`;
|
document.documentElement.style.cursor = `${resizeHandle}-resize`;
|
||||||
isResizingElements = true;
|
isResizingElements = true;
|
||||||
} else {
|
} else {
|
||||||
|
// clear selection if shift is not clicked
|
||||||
|
if (!e.shiftKey) {
|
||||||
|
elements = clearSelection(elements);
|
||||||
|
}
|
||||||
const hitElement = getElementAtPosition(elements, x, y);
|
const hitElement = getElementAtPosition(elements, x, y);
|
||||||
|
|
||||||
// If we click on something
|
// If we click on something
|
||||||
if (hitElement) {
|
if (hitElement) {
|
||||||
if (hitElement.isSelected) {
|
// deselect if item is selected
|
||||||
// If that element is already selected, do nothing,
|
// if shift is not clicked, this will always return true
|
||||||
// we're likely going to drag it
|
// otherwise, it will trigger selection based on current
|
||||||
} else {
|
// state of the box
|
||||||
// We unselect every other elements unless shift is pressed
|
hitElement.isSelected = !hitElement.isSelected;
|
||||||
if (!e.shiftKey) {
|
|
||||||
elements = clearSelection(elements);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// No matter what, we select it
|
// No matter what, we select it
|
||||||
hitElement.isSelected = true;
|
|
||||||
// We duplicate the selected element if alt is pressed on Mouse down
|
// We duplicate the selected element if alt is pressed on Mouse down
|
||||||
if (e.altKey) {
|
if (e.altKey) {
|
||||||
elements = [
|
elements = [
|
||||||
|
@ -805,9 +805,6 @@ export class App extends React.Component<{}, AppState> {
|
||||||
}, [] as typeof elements)
|
}, [] as typeof elements)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// If we don't click on anything, let's remove all the selected elements
|
|
||||||
elements = clearSelection(elements);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isDraggingElements = someElementIsSelected(elements);
|
isDraggingElements = someElementIsSelected(elements);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue