diff --git a/CHANGES.md b/CHANGES.md index 202e1a813..3e92235c3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -89,6 +89,7 @@ time being. - Fix issue when exporting libraries when merging libraries [Taiga #8758](https://tree.taiga.io/project/penpot/issue/8758) - Fix problem with comments max length [Taiga #8778](https://tree.taiga.io/project/penpot/issue/8778) - Fix copy/paste images in Safari [Taiga #8771](https://tree.taiga.io/project/penpot/issue/8771) +- Fix swap when the copy is the only child of a group [#5075](https://github.com/penpot/penpot/issues/5075) ## 2.1.5 diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 9df975937..8f7bd5b31 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -545,6 +545,7 @@ (d/update-in-when [pid :shapes] d/without-obj sid) (d/update-in-when [pid :shapes] d/vec-without-nils) (cond-> component? (d/update-when pid #(dissoc % :remote-synced)))))))) + (update-parent-id [objects id] (-> objects (d/update-when id assoc :parent-id parent-id))) diff --git a/common/src/app/common/logic/shapes.cljc b/common/src/app/common/logic/shapes.cljc index f5d38f0c2..00f1395eb 100644 --- a/common/src/app/common/logic/shapes.cljc +++ b/common/src/app/common/logic/shapes.cljc @@ -158,7 +158,11 @@ empty-parents ;; Any parent whose children are all deleted, must be deleted too. - (into (d/ordered-set) (find-all-empty-parents #{})) + ;; Unless we are during a component swap: in this case we are replacing a shape by + ;; other one, so must not delete empty parents. + (if-not component-swap + (into (d/ordered-set) (find-all-empty-parents #{})) + #{}) components-to-delete (if components-v2