diff --git a/common/src/app/common/types/modifiers.cljc b/common/src/app/common/types/modifiers.cljc index 8b2d27445..2b994d6f6 100644 --- a/common/src/app/common/types/modifiers.cljc +++ b/common/src/app/common/types/modifiers.cljc @@ -229,7 +229,7 @@ (scale-content value))) (defn change-dimensions-modifiers - [shape attr value] + [{:keys [transform transform-inverse] :as shape} attr value] (us/assert map? shape) (us/assert #{:width :height} attr) (us/assert number? value) @@ -245,22 +245,17 @@ (-> size (assoc :height value) (assoc :width (* value proportion))))) + width (:width new-size) height (:height new-size) - shape-transform (:transform shape) - shape-transform-inv (:transform-inverse shape) - shape-center (gco/center-shape shape) {sr-width :width sr-height :height} (:selrect shape) - origin (cond-> (gpt/point (:selrect shape)) - (some? shape-transform) - (gmt/transform-point-center shape-center shape-transform)) + origin (-> shape :points first) + scalex (/ width sr-width) + scaley (/ height sr-height)] - scalev (gpt/divide (gpt/point width height) - (gpt/point sr-width sr-height))] - - (resize-modifiers scalev origin shape-transform shape-transform-inv))) + (resize-modifiers (gpt/point scalex scaley) origin transform transform-inverse))) (defn change-orientation-modifiers [shape orientation] @@ -437,5 +432,3 @@ (as-> shape $ (reduce apply-modifier $ (:structure-parent modifiers)) (reduce apply-modifier $ (:structure-child modifiers)))))) - - diff --git a/frontend/src/app/main/data/workspace/texts.cljs b/frontend/src/app/main/data/workspace/texts.cljs index 0527184a0..d4cf5995f 100644 --- a/frontend/src/app/main/data/workspace/texts.cljs +++ b/frontend/src/app/main/data/workspace/texts.cljs @@ -394,7 +394,7 @@ ptk/UpdateEvent (update [_ state] (let [ids (keys (::update-position-data state))] - (update state :workspace-text-modifiers #(apply dissoc % ids)))) + (update state :workspace-text-modifier #(apply dissoc % ids)))) ptk/WatchEvent (watch [_ state _] diff --git a/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts_html.cljs b/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts_html.cljs index 96d946f26..8dc6f1e82 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts_html.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts_html.cljs @@ -33,7 +33,7 @@ (-> shape (cond-> (some? (meta (:position-data shape))) (with-meta (meta (:position-data shape)))) - (dissoc :position-data :transform :transform-inverse))) + (dissoc :position-data))) (defn fix-position [shape modifier] (let [shape' (-> shape @@ -92,20 +92,26 @@ (defn- update-text-modifier [{:keys [grow-type id]} node] - (p/let [position-data (tsp/calc-position-data id) - props {:position-data position-data} + (ts/raf + #(p/let [position-data (tsp/calc-position-data id) + props {:position-data position-data} - props - (if (contains? #{:auto-height :auto-width} grow-type) - (let [{:keys [width height]} (-> (dom/query node ".paragraph-set") (dom/get-client-size)) - width (mth/ceil width) - height (mth/ceil height)] - (if (and (not (mth/almost-zero? width)) (not (mth/almost-zero? height))) - (assoc props :width width :height height) - props)) - props)] + props + (if (contains? #{:auto-height :auto-width} grow-type) + (let [{:keys [width height]} (-> (dom/query node ".paragraph-set") (dom/get-client-size)) + width (mth/ceil width) + height (mth/ceil height)] + (if (and (not (mth/almost-zero? width)) (not (mth/almost-zero? height))) + (cond-> props + (= grow-type :auto-width) + (assoc :width width) - (st/emit! (dwt/update-text-modifier id props)))) + (or (= grow-type :auto-height) (= grow-type :auto-width)) + (assoc :height height)) + props)) + props)] + + (st/emit! (dwt/update-text-modifier id props))))) (mf/defc text-container {::mf/wrap-props false @@ -163,10 +169,9 @@ handle-update-modifier (mf/use-callback update-text-modifier) handle-update-shape (mf/use-callback update-text-shape)] - [:* (for [{:keys [id] :as shape} changed-texts] - [:& text-container {:shape (gsh/transform-shape shape) + [:& text-container {:shape shape :on-update (if (some? (get modifiers (:id shape))) handle-update-modifier handle-update-shape)