Shift drag to add to selection (#350)

This commit is contained in:
Timur Khazamov 2020-01-13 00:56:10 +05:00 committed by Christopher Chedeau
parent 58ad6d741d
commit ce467f7b65
3 changed files with 23 additions and 12 deletions

View file

@ -15,7 +15,7 @@ import {
import {
clearSelection,
deleteSelectedElements,
setSelection,
getElementsWithinSelection,
isOverScrollBars,
restoreFromLocalStorage,
saveToLocalStorage,
@ -746,13 +746,24 @@ export class App extends React.Component<{}, AppState> {
this.state.scrollY;
draggingElement.width = width;
// Make a perfect square or circle when shift is enabled
draggingElement.height = e.shiftKey
? Math.abs(width) * Math.sign(height)
: height;
draggingElement.height =
// Shift key on selection must add items to selection
e.shiftKey && this.state.elementType !== "selection"
? Math.abs(width) * Math.sign(height)
: height;
draggingElement.shape = null;
if (this.state.elementType === "selection") {
elements = setSelection(elements, draggingElement);
const elementsWithinSelection = getElementsWithinSelection(
elements,
draggingElement
);
if (!e.shiftKey) {
elements = clearSelection(elements);
}
elementsWithinSelection.forEach(
element => (element.isSelected = true)
);
}
// We don't want to save history when moving an element
history.skipRecording();