diff --git a/packages/excalidraw/actions/actionDuplicateSelection.tsx b/packages/excalidraw/actions/actionDuplicateSelection.tsx index 194980f2c..3cd45e08e 100644 --- a/packages/excalidraw/actions/actionDuplicateSelection.tsx +++ b/packages/excalidraw/actions/actionDuplicateSelection.tsx @@ -2,7 +2,7 @@ import { ToolButton } from "../components/ToolButton"; import { DuplicateIcon } from "../components/icons"; import { DEFAULT_GRID_SIZE } from "../constants"; import { getNonDeletedElements } from "../element"; -import { isBoundToContainer } from "../element/typeChecks"; +import { isBoundToContainer, isLinearElement } from "../element/typeChecks"; import { LinearElementEditor } from "../element/linearElementEditor"; import { selectGroupsForSelectedElements } from "../groups"; import { t } from "../i18n"; @@ -52,8 +52,7 @@ export const actionDuplicateSelection = register({ } } - const origElements: ExcalidrawElement[] = elements.slice(); - const clonedElements = duplicateElements(elements, { + const duplicatedElements = duplicateElements(elements, { idsOfElementsToDuplicate: arrayToMap( getSelectedElements(elements, appState, { includeBoundTextElement: true, @@ -68,7 +67,9 @@ export const actionDuplicateSelection = register({ }), }); - let nextElements = origElements.concat(clonedElements); + let nextElements = (elements as ExcalidrawElement[]) + .slice() + .concat(duplicatedElements); if (app.props.onDuplicate && nextElements) { const mappedElements = app.props.onDuplicate(nextElements, elements); @@ -77,38 +78,22 @@ export const actionDuplicateSelection = register({ } } - nextElements = syncMovedIndices(nextElements, arrayToMap(clonedElements)); - // clonedElements - // .filter((e) => e.type === "text") - // .forEach((e) => { - // console.log(JSON.stringify(e.boundElements)); - // }); - // console.log("----"); - // nextElements - // .filter((e) => e.type === "text") - // .forEach((e) => { - // console.log(JSON.stringify(e.boundElements)); - // }); - const nextElementsToSelect = - excludeElementsInFramesFromSelection(clonedElements); - return { - elements: nextElements, + elements: syncMovedIndices(nextElements, arrayToMap(duplicatedElements)), appState: { ...appState, - ...updateLinearElementEditors(nextElements), + ...updateLinearElementEditors(duplicatedElements), ...selectGroupsForSelectedElements( { editingGroupId: appState.editingGroupId, - selectedElementIds: nextElementsToSelect.reduce( - (acc: Record, element) => { - if (!isBoundToContainer(element)) { - acc[element.id] = true; - } - return acc; - }, - {}, - ), + selectedElementIds: excludeElementsInFramesFromSelection( + duplicatedElements, + ).reduce((acc: Record, element) => { + if (!isBoundToContainer(element)) { + acc[element.id] = true; + } + return acc; + }, {}), }, getNonDeletedElements(nextElements), appState, diff --git a/packages/excalidraw/element/duplicate.ts b/packages/excalidraw/element/duplicate.ts index 74cc5d5ae..c12bcb1c1 100644 --- a/packages/excalidraw/element/duplicate.ts +++ b/packages/excalidraw/element/duplicate.ts @@ -27,7 +27,6 @@ import { bumpVersion } from "./mutateElement"; import { hasBoundTextElement, - isArrowElement, isBoundToContainer, isElbowArrow, isFrameLikeElement, @@ -321,10 +320,6 @@ export const duplicateElements = ( duplicatedElementsMap: NonDeletedSceneElementsMap, ) => { for (const element of newElements) { - if (!isArrowElement(element)) { - continue; - } - if ("boundElements" in element && element.boundElements) { Object.assign(element, { boundElements: element.boundElements.reduce(