diff --git a/CHANGES.md b/CHANGES.md index 7ee9836bd..7d22d1195 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -74,7 +74,8 @@ - Fix new-file button on project not redirecting to the new file [Taiga #5610](https://tree.taiga.io/project/penpot/issue/5610) - Fix retrieve user comments in dashboard [Taiga #5607](https://tree.taiga.io/project/penpot/issue/5607) - Locks shapes when moved inside a locked parent [Taiga #5252](https://tree.taiga.io/project/penpot/issue/5252) - +- Fix rotate several elements in bulk [Taiga #5165](https://tree.taiga.io/project/penpot/issue/5165) + ### :arrow_up: Deps updates - Update google fonts catalog (at 2023/07/06) [Taiga #5592](https://tree.taiga.io/project/penpot/issue/5592) diff --git a/frontend/src/app/main/data/workspace/modifiers.cljs b/frontend/src/app/main/data/workspace/modifiers.cljs index a27f9c4d1..8f86d72b7 100644 --- a/frontend/src/app/main/data/workspace/modifiers.cljs +++ b/frontend/src/app/main/data/workspace/modifiers.cljs @@ -371,6 +371,32 @@ (assoc state :workspace-modifiers modif-tree)))))) +;; This function is similar to set-rotation-modifiers but: +;; - It consideres the center for everyshape instead of the center of the total selrect +;; - The angle param is the desired final value, not a delta +(defn set-delta-rotation-modifiers + ([angle shapes] + (ptk/reify ::set-delta-rotation-modifiers + ptk/UpdateEvent + (update [_ state] + (let [objects (wsh/lookup-page-objects state) + ids + (->> shapes + (remove #(get % :blocked false)) + (filter #((cpc/editable-attrs (:type %)) :rotation)) + (map :id)) + + get-modifier + (fn [shape] + (let [delta (- angle (:rotation shape)) + center (gsh/center-shape shape)] + (ctm/rotation-modifiers shape center delta))) + + modif-tree + (-> (build-modif-tree ids objects get-modifier) + (gsh/set-objects-modifiers objects))] + + (assoc state :workspace-modifiers modif-tree)))))) (defn apply-modifiers ([] diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index 862cb4599..ad43c6bfc 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -343,12 +343,10 @@ (let [page-id (:current-page-id state) objects (wsh/lookup-page-objects state page-id) - rotate-shape (fn [shape] - (let [delta (- rotation (:rotation shape))] - (dwm/set-rotation-modifiers delta [shape])))] + shapes (->> ids (map #(get objects %)))] (rx/concat - (rx/from (->> ids (map #(get objects %)) (map rotate-shape))) - (rx/of (dwm/apply-modifiers))))))) + (rx/of (dwm/set-delta-rotation-modifiers rotation shapes)) + (rx/of (dwm/apply-modifiers))))))) ;; -- Move ----------------------------------------------------------