diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 24b48c0aa..91117c622 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -392,4 +392,4 @@ (l/derived :workspace-text-modifier st/state)) (defn workspace-text-modifier-by-id [id] - (l/derived #(get % id) workspace-text-modifier)) + (l/derived #(get % id) workspace-text-modifier =)) diff --git a/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts.cljs b/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts.cljs index fea2ad1d9..a2bcc391e 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts.cljs @@ -87,7 +87,8 @@ (st/emit! (dwt/update-text-modifier id props)))) (mf/defc text-container - {::mf/wrap-props false} + {::mf/wrap-props false + ::mf/wrap [mf/memo]} [props] (let [shape (obj/get props "shape") on-update (obj/get props "on-update") @@ -98,6 +99,7 @@ (fn [node] (when (some? node) (on-update shape node))))] + [:& fo/text-shape {:key (str "shape-" (:id shape)) :ref handle-update :shape shape @@ -144,10 +146,29 @@ (-> (mf/deref refs/workspace-editor-state) (get (:id shape))) + text-modifier-ref + (mf/use-memo (mf/deps (:id shape)) #(refs/workspace-text-modifier-by-id (:id shape))) + + text-modifier + (mf/deref text-modifier-ref) + shape (cond-> shape (some? editor-state) (update-with-editor-state editor-state)) + ;; When we have a text with grow-type :auto-height we need to check the correct height + ;; otherwise the center alignment will break + shape + (if (or (not= :auto-height (:grow-type shape)) (empty? text-modifier)) + shape + (let [tr-shape (dwt/apply-text-modifier shape text-modifier)] + (cond-> shape + ;; we only change the height otherwise could cause problems with the other fields + (some? text-modifier) + (assoc :height (:height tr-shape))))) + + shape (hooks/use-equal-memo shape) + handle-update-shape (mf/use-callback update-text-modifier)] (mf/use-effect