From 8b3062be0b4fa9e0730932021e30e829817affd8 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 28 Apr 2022 15:30:22 +0200 Subject: [PATCH] :bug: Fix problem when resizing a group with texts with auto-width/height --- CHANGES.md | 1 + .../src/app/main/data/workspace/texts.cljs | 12 +++- .../app/main/data/workspace/transforms.cljs | 68 ++++++++++++------- 3 files changed, 52 insertions(+), 29 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 63afd84d9..cc877d0b5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -97,6 +97,7 @@ - Fix error when drawing curves with only one point [Taiga #3282](https://tree.taiga.io/project/penpot/issue/3282) - Fix issue with paste ordering sometimes not being respected [Taiga #3268](https://tree.taiga.io/project/penpot/issue/3268) - Fix problem when export/importing guides attached to frame [#1838](https://github.com/penpot/penpot/issues/1838) +- Fix problem when resizing a group with texts with auto-width/height [#3171](https://tree.taiga.io/project/penpot/issue/3171) ### :arrow_up: Deps updates ### :heart: Community contributions by (Thank you!) diff --git a/frontend/src/app/main/data/workspace/texts.cljs b/frontend/src/app/main/data/workspace/texts.cljs index 4b3cf805a..0d46f915a 100644 --- a/frontend/src/app/main/data/workspace/texts.cljs +++ b/frontend/src/app/main/data/workspace/texts.cljs @@ -384,6 +384,11 @@ (defn commit-position-data [] (ptk/reify ::commit-position-data + ptk/UpdateEvent + (update [_ state] + (let [ids (keys (::update-position-data state))] + (update state :workspace-text-modifiers #(apply dissoc % ids)))) + ptk/WatchEvent (watch [_ state _] (let [position-data (::update-position-data state)] @@ -404,9 +409,10 @@ (ptk/reify ::update-position-data ptk/UpdateEvent (update [_ state] - (if (nil? (::update-position-data-debounce state)) - (assoc state ::update-position-data-debounce start) - (assoc-in state [::update-position-data id] position-data))) + (let [state (assoc-in state [:workspace-text-modifier id :position-data] position-data)] + (if (nil? (::update-position-data-debounce state)) + (assoc state ::update-position-data-debounce start) + (assoc-in state [::update-position-data id] position-data)))) ptk/WatchEvent (watch [_ state stream] diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index 25a0a9d22..058f1b42c 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -166,6 +166,20 @@ (update state :workspace-modifiers #(reduce update-shape % shapes))))))) +(defn- update-grow-type + [shape old-shape] + (let [auto-width? (= :auto-width (:grow-type shape)) + auto-height? (= :auto-height (:grow-type shape)) + + changed-width? (not (mth/close? (:width shape) (:width old-shape))) + changed-height? (not (mth/close? (:height shape) (:height old-shape))) + + change-to-fixed? (or (and auto-width? (or changed-height? changed-width?)) + (and auto-height? changed-height?))] + (cond-> shape + change-to-fixed? + (assoc :grow-type :fixed)))) + (defn- apply-modifiers [ids] (us/verify (s/coll-of uuid?) ids) @@ -182,27 +196,33 @@ (rx/of (dwu/start-undo-transaction) (dwg/move-frame-guides ids-with-children) (dch/update-shapes - ids-with-children - (fn [shape] - (let [modif (get object-modifiers (:id shape))] - (gsh/transform-shape (merge shape modif)))) - {:reg-objects? true - :ignore-tree ignore-tree - ;; Attributes that can change in the transform. This way we don't have to check - ;; all the attributes - :attrs [:selrect - :points - :x - :y - :width - :height - :content - :transform - :transform-inverse - :rotation - :position-data - :flip-x - :flip-y]}) + ids-with-children + (fn [shape] + (let [modif (get object-modifiers (:id shape)) + text-shape? (cph/text-shape? shape)] + (-> shape + (merge modif) + (gsh/transform-shape) + (cond-> text-shape? + (update-grow-type shape))))) + {:reg-objects? true + :ignore-tree ignore-tree + ;; Attributes that can change in the transform. This way we don't have to check + ;; all the attributes + :attrs [:selrect + :points + :x + :y + :width + :height + :content + :transform + :transform-inverse + :rotation + :position-data + :flip-x + :flip-y + :grow-type]}) (clear-local-transform) (dwu/commit-undo-transaction)))))) @@ -483,12 +503,8 @@ focus (:workspace-focus-selected state) zoom (get-in state [:workspace-local :zoom] 1) objects (wsh/lookup-page-objects state page-id) - resizing-shapes (map #(get objects %) ids) - text-shapes-ids (->> resizing-shapes - (filter #(= :text (:type %))) - (map :id))] + resizing-shapes (map #(get objects %) ids)] (rx/concat - (rx/of (dch/update-shapes text-shapes-ids #(assoc % :grow-type :fixed))) (->> ms/mouse-position (rx/with-latest-from ms/mouse-position-shift ms/mouse-position-alt) (rx/map normalize-proportion-lock)