Fix alt-duplicate (#326)

We need to unselect all the previous elements and select all the new ones. Also made sure that the shape is regenerated when the element is duplicated
This commit is contained in:
Christopher Chedeau 2020-01-11 19:35:06 -08:00 committed by GitHub
parent 8785bef523
commit 407f00bbd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 11 deletions

View File

@ -37,6 +37,7 @@ export function newElement(
export function duplicateElement(element: ReturnType<typeof newElement>) {
const copy = { ...element };
delete copy.shape;
copy.id = nanoid();
copy.seed = randomSeed();
return copy;

View File

@ -520,20 +520,20 @@ export class App extends React.Component<{}, AppState> {
elementIsAddedToSelection = true;
}
// No matter what, we select it
// We duplicate the selected element if alt is pressed on Mouse down
if (e.altKey) {
elements = [
...elements,
...elements.reduce((duplicates, element) => {
if (element.isSelected) {
duplicates = duplicates.concat(
duplicateElement(element)
);
element.isSelected = false;
}
return duplicates;
}, [] as typeof elements)
...elements.map(element => ({
...element,
isSelected: false
})),
...elements
.filter(element => element.isSelected)
.map(element => {
const newElement = duplicateElement(element);
newElement.isSelected = true;
return newElement;
})
];
}
}