diff --git a/packages/excalidraw/actions/actionDuplicateSelection.tsx b/packages/excalidraw/actions/actionDuplicateSelection.tsx index 93d56881a..32954471b 100644 --- a/packages/excalidraw/actions/actionDuplicateSelection.tsx +++ b/packages/excalidraw/actions/actionDuplicateSelection.tsx @@ -105,7 +105,17 @@ 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); @@ -373,97 +383,6 @@ const _duplicateElements = ( // oldIdToDuplicatedId, // ); - // newElements - // .map((element) => { - // oldElements.includes(element) && console.error("oldElements", element); - - // if (isArrowElement(element)) { - // const updates: Mutable> = {}; - - // if (element.startBinding) { - // const startCloneElementId = oldIdToDuplicatedId.get( - // element.startBinding.elementId, - // ); - - // if (startCloneElementId) { - // // The connected element was duplicated, so we need to update the binding - // updates.startBinding = { - // ...element.startBinding, - // elementId: startCloneElementId, - // }; - // } else { - // // The connected element was not duplicated, so we need to remove the binding - // updates.startBinding = null; - // } - // } - - // if (element.endBinding) { - // const endCloneElementId = oldIdToDuplicatedId.get( - // element.endBinding.elementId, - // ); - - // if (endCloneElementId) { - // // The connected element was duplicated, so we need to update the binding - // updates.endBinding = { - // ...element.endBinding, - // elementId: endCloneElementId, - // }; - // } else { - // // The connected element was not duplicated, so we need to remove the binding - // updates.endBinding = null; - // } - // } - - // if (Object.keys(updates).length > 0) { - // // Only update the element if there are updates to apply - // return { - // element, - // updates, - // }; - // } - // } else if (isBindableElement(element)) { - // if (element.boundElements?.length) { - // const clonedBoundElements = element.boundElements - // ?.map((definition) => { - // const clonedBoundElementId = oldIdToDuplicatedId.get( - // definition.id, - // ); - // if (clonedBoundElementId) { - // // The connected element was duplicated, so we need to update the binding - // return { - // ...definition, - // id: clonedBoundElementId, - // }; - // } - - // // The connected element was not duplicated, so we need to remove the binding - // return null; - // }) - // .filter( - // (definition): definition is BoundElement => definition !== null, - // ); - - // if (clonedBoundElements?.length) { - // return { - // element, - // updates: { - // boundElements: clonedBoundElements, - // }, - // }; - // } - // } - // } - - // return null; - // }) - // .forEach((change) => { - // if (!change) { - // return; - // } - - // mutateElement(change.element, change.updates); - // }); - bindElementsToFramesAfterDuplication( elementsWithClones, oldElements, diff --git a/packages/excalidraw/element/duplicate.ts b/packages/excalidraw/element/duplicate.ts index 72586dae4..66eb77292 100644 --- a/packages/excalidraw/element/duplicate.ts +++ b/packages/excalidraw/element/duplicate.ts @@ -314,12 +314,6 @@ export const duplicateElements = ( // --------------------------------------------------------------------------- - bindTextToShapeAfterDuplication( - elementsWithClones, - oldElements, - oldIdToDuplicatedId, - ); - const fixBindingsAfterDuplication = ( newElements: Mutable[], oldIdToDuplicatedId: Map, @@ -385,6 +379,12 @@ export const duplicateElements = ( duplicatedElementsMap as NonDeletedSceneElementsMap, ); + bindTextToShapeAfterDuplication( + elementsWithClones, + oldElements, + oldIdToDuplicatedId, + ); + bindElementsToFramesAfterDuplication( elementsWithClones, oldElements,