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:
parent
8785bef523
commit
407f00bbd5
@ -37,6 +37,7 @@ export function newElement(
|
|||||||
|
|
||||||
export function duplicateElement(element: ReturnType<typeof newElement>) {
|
export function duplicateElement(element: ReturnType<typeof newElement>) {
|
||||||
const copy = { ...element };
|
const copy = { ...element };
|
||||||
|
delete copy.shape;
|
||||||
copy.id = nanoid();
|
copy.id = nanoid();
|
||||||
copy.seed = randomSeed();
|
copy.seed = randomSeed();
|
||||||
return copy;
|
return copy;
|
||||||
|
@ -520,20 +520,20 @@ export class App extends React.Component<{}, AppState> {
|
|||||||
elementIsAddedToSelection = true;
|
elementIsAddedToSelection = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// No matter what, we select it
|
|
||||||
// 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 = [
|
||||||
...elements,
|
...elements.map(element => ({
|
||||||
...elements.reduce((duplicates, element) => {
|
...element,
|
||||||
if (element.isSelected) {
|
isSelected: false
|
||||||
duplicates = duplicates.concat(
|
})),
|
||||||
duplicateElement(element)
|
...elements
|
||||||
);
|
.filter(element => element.isSelected)
|
||||||
element.isSelected = false;
|
.map(element => {
|
||||||
}
|
const newElement = duplicateElement(element);
|
||||||
return duplicates;
|
newElement.isSelected = true;
|
||||||
}, [] as typeof elements)
|
return newElement;
|
||||||
|
})
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user