|
@@ -10,6 +10,7 @@ import { t } from "../i18n";
|
|
|
import { getShortcutKey } from "../utils";
|
|
|
import { LinearElementEditor } from "../element/linearElementEditor";
|
|
|
import { mutateElement } from "../element/mutateElement";
|
|
|
+import { selectGroupsForSelectedElements } from "../groups";
|
|
|
|
|
|
export const actionDuplicateSelection = register({
|
|
|
name: "duplicateSelection",
|
|
@@ -50,28 +51,39 @@ export const actionDuplicateSelection = register({
|
|
|
}
|
|
|
|
|
|
const groupIdMap = new Map();
|
|
|
+ const newElements: ExcalidrawElement[] = [];
|
|
|
+ const finalElements = elements.reduce(
|
|
|
+ (acc: Array<ExcalidrawElement>, element: ExcalidrawElement) => {
|
|
|
+ if (appState.selectedElementIds[element.id]) {
|
|
|
+ const newElement = duplicateElement(
|
|
|
+ appState.editingGroupId,
|
|
|
+ groupIdMap,
|
|
|
+ element,
|
|
|
+ {
|
|
|
+ x: element.x + 10,
|
|
|
+ y: element.y + 10,
|
|
|
+ },
|
|
|
+ );
|
|
|
+ newElements.push(newElement);
|
|
|
+ return acc.concat([element, newElement]);
|
|
|
+ }
|
|
|
+ return acc.concat(element);
|
|
|
+ },
|
|
|
+ [],
|
|
|
+ );
|
|
|
return {
|
|
|
- appState,
|
|
|
- elements: elements.reduce(
|
|
|
- (acc: Array<ExcalidrawElement>, element: ExcalidrawElement) => {
|
|
|
- if (appState.selectedElementIds[element.id]) {
|
|
|
- const newElement = duplicateElement(
|
|
|
- appState.editingGroupId,
|
|
|
- groupIdMap,
|
|
|
- element,
|
|
|
- {
|
|
|
- x: element.x + 10,
|
|
|
- y: element.y + 10,
|
|
|
- },
|
|
|
- );
|
|
|
- appState.selectedElementIds[newElement.id] = true;
|
|
|
- delete appState.selectedElementIds[element.id];
|
|
|
- return acc.concat([element, newElement]);
|
|
|
- }
|
|
|
- return acc.concat(element);
|
|
|
+ appState: selectGroupsForSelectedElements(
|
|
|
+ {
|
|
|
+ ...appState,
|
|
|
+ selectedGroupIds: {},
|
|
|
+ selectedElementIds: newElements.reduce((acc, element) => {
|
|
|
+ acc[element.id] = true;
|
|
|
+ return acc;
|
|
|
+ }, {} as any),
|
|
|
},
|
|
|
- [],
|
|
|
+ getNonDeletedElements(finalElements),
|
|
|
),
|
|
|
+ elements: finalElements,
|
|
|
commitToHistory: true,
|
|
|
};
|
|
|
},
|