瀏覽代碼

fix cloning element.points (#744)

David Luzar 5 年之前
父節點
當前提交
6dd3620dd6
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      src/element/newElement.ts

+ 6 - 1
src/element/newElement.ts

@@ -65,8 +65,13 @@ export function newTextElement(
 export function duplicateElement(element: ReturnType<typeof newElement>) {
   const copy = {
     ...element,
-    points: JSON.parse(JSON.stringify(element.points)),
   };
+  if ("points" in copy) {
+    copy.points = Array.isArray(element.points)
+      ? JSON.parse(JSON.stringify(element.points))
+      : element.points;
+  }
+
   delete copy.shape;
   copy.id = nanoid();
   copy.seed = randomSeed();