From ab5323d8734084ce7f3c18e5a9d9dc2acf5a9771 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 4 Dec 2020 13:58:48 +0100 Subject: [PATCH] :sparkles: Improves resize observer --- frontend/src/app/main/ui/workspace/shapes/text.cljs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/shapes/text.cljs b/frontend/src/app/main/ui/workspace/shapes/text.cljs index 46121983a3..6561633082 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text.cljs @@ -23,11 +23,15 @@ [app.main.ui.workspace.shapes.common :as common] [app.main.ui.workspace.shapes.text.editor :as editor] [app.util.dom :as dom] + [app.util.logging :as log] [app.util.object :as obj] [app.util.timers :as timers] [beicon.core :as rx] [rumext.alpha :as mf])) +;; Change this to :info :debug or :trace to debug this module +(log/set-level! :warn) + ;; --- Events (defn use-double-click [{:keys [id]} selected?] @@ -44,7 +48,7 @@ (mf/defc text-wrapper {::mf/wrap-props false} [props] - (let [{:keys [id x y width height] :as shape} (unchecked-get props "shape") + (let [{:keys [id name x y width height] :as shape} (unchecked-get props "shape") selected-iref (mf/use-memo (mf/deps (:id shape)) #(refs/make-selected-ref (:id shape))) selected? (mf/deref selected-iref) @@ -63,7 +67,7 @@ handle-pointer-leave (we/use-pointer-leave shape) handle-double-click (use-double-click shape selected?) - paragraph-ref (mf/use-var nil) + paragraph-ref (mf/use-state nil) handle-resize-text (mf/use-callback @@ -93,9 +97,9 @@ (fn [] (when-let [paragraph-node @paragraph-ref] (let [observer (js/ResizeObserver. handle-resize-text)] + (log/debug :msg "Attach resize observer" :shape-id id :shape-name name) (.observe observer paragraph-node) - #(.disconnect observer))) - )) + #(.disconnect observer))))) [:> shape-container {:shape shape} ;; We keep hidden the shape when we're editing so it keeps track of the size