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`;
|
||||
isResizingElements = true;
|
||||
} else {
|
||||
// clear selection if shift is not clicked
|
||||
if (!e.shiftKey) {
|
||||
elements = clearSelection(elements);
|
||||
}
|
||||
const hitElement = getElementAtPosition(elements, x, y);
|
||||
|
||||
// If we click on something
|
||||
if (hitElement) {
|
||||
if (hitElement.isSelected) {
|
||||
// If that element is already selected, do nothing,
|
||||
// we're likely going to drag it
|
||||
} else {
|
||||
// We unselect every other elements unless shift is pressed
|
||||
if (!e.shiftKey) {
|
||||
elements = clearSelection(elements);
|
||||
}
|
||||
}
|
||||
// deselect if item is selected
|
||||
// if shift is not clicked, this will always return true
|
||||
// otherwise, it will trigger selection based on current
|
||||
// state of the box
|
||||
hitElement.isSelected = !hitElement.isSelected;
|
||||
|
||||
// No matter what, we select it
|
||||
hitElement.isSelected = true;
|
||||
// We duplicate the selected element if alt is pressed on Mouse down
|
||||
if (e.altKey) {
|
||||
elements = [
|
||||
|
@ -805,9 +805,6 @@ export class App extends React.Component<{}, AppState> {
|
|||
}, [] as typeof elements)
|
||||
];
|
||||
}
|
||||
} else {
|
||||
// If we don't click on anything, let's remove all the selected elements
|
||||
elements = clearSelection(elements);
|
||||
}
|
||||
|
||||
isDraggingElements = someElementIsSelected(elements);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue