Skip to content

Commit

Permalink
fix(duplicate-element): fix console error after duplicate content (#839)
Browse files Browse the repository at this point in the history
  • Loading branch information
pubuzhixing8 committed Apr 19, 2024
1 parent 3ff6179 commit 2a33c1c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-weeks-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@plait/core': patch
---

clone the duplicated content before inserting to resolve console error
6 changes: 4 additions & 2 deletions packages/core/src/utils/fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ export const duplicateElements = (board: PlaitBoard, elements?: PlaitElement[])
const selectedElements = elements || getSelectedElements(board);
const rectangle = getRectangleByElements(board, selectedElements, false);
const clipboardContext = board.buildFragment(null, rectangle, 'copy');
clipboardContext &&
const stringifiedContext = clipboardContext && JSON.stringify(clipboardContext);
const clonedContext = stringifiedContext && JSON.parse(stringifiedContext);
clonedContext &&
board.insertFragment(
{
...clipboardContext,
...clonedContext,
text: undefined
},
[rectangle.x + rectangle.width / 2, rectangle.y + rectangle.height / 2]
Expand Down

0 comments on commit 2a33c1c

Please sign in to comment.