From 9be569c54c4ebdb0caa50b49f8a1aecae26b6f40 Mon Sep 17 00:00:00 2001 From: Alonso Torres Date: Thu, 8 May 2025 13:39:47 +0200 Subject: [PATCH] :bug: Fix problem when duplicating grid layout (#6426) --- CHANGES.md | 1 + common/src/app/common/logic/libraries.cljc | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1374a448f2..3078c8577d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -43,6 +43,7 @@ - Fix Out of Sync Token Value & Color Picker [Github #102](https://github.com/tokens-studio/penpot/issues/102) - Fix Color should preserve color space [Github #69](https://github.com/tokens-studio/penpot/issues/69) - Fix cannot rename Design Token Sets when group of same name exists [Taiga Issue #10773](https://tree.taiga.io/project/penpot/issue/10773) +- Fix problem when duplicating grid layout [Github #6391](https://github.com/penpot/penpot/issues/6391) ## 2.6.2 (Unreleased) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 9a08f7b8b0..631db173a1 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -216,10 +216,12 @@ "Generate changes to create a new instance from a component." ([changes objects file-id component-id position page libraries] (generate-instantiate-component changes objects file-id component-id position page libraries nil nil nil {})) - - ([changes objects file-id component-id position page libraries old-id parent-id frame-id + ([changes objects file-id component-id position page libraries old-id parent-id frame-id params] + (generate-instantiate-component changes objects file-id component-id position page libraries old-id parent-id frame-id {} params)) + ([changes objects file-id component-id position page libraries old-id parent-id frame-id ids-map {:keys [force-frame?] :or {force-frame? false}}] + (let [component (ctf/get-component libraries file-id component-id) library (get libraries file-id) parent (when parent-id (get objects parent-id)) @@ -239,6 +241,9 @@ (:data library) position (cond-> {} + (contains? ids-map old-id) + (assoc :force-id (get ids-map old-id)) + force-frame? (assoc :force-frame-id frame-id))) @@ -260,8 +265,11 @@ (cond-> (pcb/add-object changes first-shape {:ignore-touched true}) (some? old-id) (pcb/amend-last-change #(assoc % :old-id old-id))) + duplicated-parent? + (->> ids-map vals (some #(= % (:parent-id first-shape)))) + changes - (if (ctl/grid-layout? objects (:parent-id first-shape)) + (if (and (ctl/grid-layout? objects (:parent-id first-shape)) (not duplicated-parent?)) (let [target-cell (-> position meta :cell) [row column] @@ -2234,6 +2242,7 @@ main-id parent-id frame-id + ids-map {})))] changes))