From 58ec6567ae1301f77052ba8fb5a00611ce4d309a Mon Sep 17 00:00:00 2001 From: David Luzar Date: Wed, 8 Jan 2020 18:09:02 +0100 Subject: [PATCH] ensure alt+drag duplicates all selected elems (#258) --- src/index.tsx | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index f02a091d..270128f7 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -680,21 +680,15 @@ class App extends React.Component<{}, AppState> { hitElement.isSelected = true; // We duplicate the selected element if alt is pressed on Mouse down if (e.altKey) { - const element = newElement( - hitElement.type, - hitElement.x, - hitElement.y, - hitElement.strokeColor, - hitElement.backgroundColor, - hitElement.fillStyle, - hitElement.strokeWidth, - hitElement.roughness, - hitElement.opacity, - hitElement.width, - hitElement.height + elements.push( + ...elements.reduce((duplicates, element) => { + if (element.isSelected) { + duplicates.push({ ...element }); + element.isSelected = false; + } + return duplicates; + }, [] as typeof elements) ); - - elements.push(element); } } else { // If we don't click on anything, let's remove all the selected elements