diff --git a/CHANGES.md b/CHANGES.md index cab10c3bc7..209bba9272 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ - Fix pan cursor not disabling viewport guides [Github #6985](https://github.com/penpot/penpot/issues/6985) - Fix viewport resize on locked shapes [Taiga #11974](https://tree.taiga.io/project/penpot/issue/11974) - Fix nested variant in a component doesn't keep inherited overrides [Taiga #12299](https://tree.taiga.io/project/penpot/issue/12299) +- Fix incorrect behavior of Alt + Drag for variants [Taiga #12309](https://tree.taiga.io/project/penpot/issue/12309) ## 2.11.0 (Unreleased) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 591859c688..202275703d 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -2801,7 +2801,7 @@ (defn generate-duplicate-changes "Prepare objects to duplicate: generate new id, give them unique names, move to the desired position, and recalculate parents and frames as needed." - [changes all-objects page ids delta libraries library-data file-id & {:keys [variant-props]}] + [changes all-objects page ids delta libraries library-data file-id & {:keys [variant-props alt-duplication?]}] (let [shapes (map (d/getf all-objects) ids) unames (volatile! (cfh/get-used-names (:objects page))) update-unames! (fn [new-name] (vswap! unames conj new-name)) @@ -2811,10 +2811,22 @@ ;; we calculate a new one because the components will have created new shapes. ids-map (into {} (map #(vector % (uuid/next))) all-ids) + + ;; If there is an alt-duplication of a variant, change its parent to root + ;; so the copy is made as a child of root + ;; This is because inside a variant-container can't be a copy + shapes (map (fn [shape] + (if (and alt-duplication? (ctk/is-variant? shape)) + (assoc shape :parent-id uuid/zero :frame-id nil) + shape)) + shapes) + + changes (-> changes (pcb/with-page page) (pcb/with-objects all-objects) (pcb/with-library-data library-data)) + changes (->> shapes (reduce #(generate-duplicate-shape-change %1 diff --git a/frontend/src/app/main/data/workspace/selection.cljs b/frontend/src/app/main/data/workspace/selection.cljs index bf73d148ea..16459d7408 100644 --- a/frontend/src/app/main/data/workspace/selection.cljs +++ b/frontend/src/app/main/data/workspace/selection.cljs @@ -463,7 +463,7 @@ library-data (dsh/lookup-file-data state file-id) changes (-> (pcb/empty-changes it) - (cll/generate-duplicate-changes objects page ids delta libraries library-data file-id) + (cll/generate-duplicate-changes objects page ids delta libraries library-data file-id {:alt-duplication? alt-duplication?}) (cll/generate-duplicate-changes-update-indices objects ids)) tags (or (:tags changes) #{})