diff --git a/CHANGES.md b/CHANGES.md index 59271cfbd..5befa20da 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -90,6 +90,7 @@ - Fix component name in sidebar widget [Taiga #3144](https://tree.taiga.io/project/penpot/issue/3144) - Fix resize rotated shape with top&down constraints [Taiga #3167](https://tree.taiga.io/project/penpot/issue/3167) - Fix multi user not working [Taiga #3195](https://tree.taiga.io/project/penpot/issue/3195) +- Fix guides are not duplicated with the artboard [Taiga #3072](https://tree.taiga.io/project/penpot/issue/3072) ### :arrow_up: Deps updates ### :heart: Community contributions by (Thank you!) diff --git a/frontend/src/app/main/data/workspace/common.cljs b/frontend/src/app/main/data/workspace/common.cljs index 0743d972c..3b7a99355 100644 --- a/frontend/src/app/main/data/workspace/common.cljs +++ b/frontend/src/app/main/data/workspace/common.cljs @@ -393,6 +393,11 @@ interactions))) (vals objects)) + ;; If any of the deleted shapes is a frame with guides + guides (into {} (map (juxt :id identity) (->> (get-in page [:options :guides]) + (vals) + (filter #(not (contains? ids (:frame-id %))))))) + starting-flows (filter (fn [flow] ;; If any of the deleted is a frame that starts a flow, @@ -432,6 +437,7 @@ changes (-> (pcb/empty-changes it page-id) (pcb/with-page page) (pcb/with-objects objects) + (pcb/set-page-option :guides guides) (pcb/remove-objects all-children) (pcb/remove-objects ids) (pcb/remove-objects empty-parents) diff --git a/frontend/src/app/main/data/workspace/selection.cljs b/frontend/src/app/main/data/workspace/selection.cljs index 6cc5aa6c4..5b4a2f000 100644 --- a/frontend/src/app/main/data/workspace/selection.cljs +++ b/frontend/src/app/main/data/workspace/selection.cljs @@ -274,6 +274,7 @@ (declare prepare-duplicate-frame-change) (declare prepare-duplicate-shape-change) (declare prepare-duplicate-flows) +(declare prepare-duplicate-guides) (defn prepare-duplicate-changes "Prepare objects to duplicate: generate new id, give them unique names, @@ -302,7 +303,9 @@ delta) init-changes))] - (prepare-duplicate-flows changes shapes page ids-map))) + (-> changes + (prepare-duplicate-flows shapes page ids-map) + (prepare-duplicate-guides shapes page ids-map delta)))) (defn- prepare-duplicate-change [changes objects page unames update-unames! ids-map shape delta] @@ -362,20 +365,20 @@ changes (-> (pcb/add-object changes new-obj {:ignore-touched true}) (pcb/amend-last-change #(assoc % :old-id (:id obj))))] - (reduce (fn [changes child] - (prepare-duplicate-shape-change changes - objects - page - unames - update-unames! - ids-map - child - delta - frame-id - new-id)) - changes - (map (d/getf objects) (:shapes obj)))) - changes)) + (reduce (fn [changes child] + (prepare-duplicate-shape-change changes + objects + page + unames + update-unames! + ids-map + child + delta + frame-id + new-id)) + changes + (map (d/getf objects) (:shapes obj)))) + changes)) (defn- prepare-duplicate-flows [changes shapes page ids-map] @@ -399,6 +402,32 @@ (pcb/update-page-option changes :flows update-flows)) changes))) +(defn- prepare-duplicate-guides + [changes shapes page ids-map delta] + (let [guides (get-in page [:options :guides]) + frames (->> shapes + (filter #(= (:type %) :frame))) + new-guides (reduce + (fn [g frame] + (let [new-id (ids-map (:id frame)) + new-frame (-> frame + (geom/move delta)) + new-guides (->> guides + (vals) + (filter #(= (:frame-id %) (:id frame))) + (map #(-> % + (assoc :id (uuid/next)) + (assoc :frame-id new-id) + (assoc :position (if (= (:axis %) :x) + (+ (:position %) (- (:x new-frame) (:x frame))) + (+ (:position %) (- (:y new-frame) (:y frame))))))))] + (conj g + (into {} (map (juxt :id identity) new-guides))))) + guides + frames)] + (-> (pcb/with-page changes page) + (pcb/set-page-option :guides new-guides)))) + (defn duplicate-changes-update-indices "Updates the changes to correctly set the indexes of the duplicated objects, depending on the index of the original object respect their parent."