From d0306ac92cfbc0fb7919426df5344e0f096947d7 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 4 Dec 2020 17:35:13 +0100 Subject: [PATCH] :bug: Fixes some issues with text shape --- .../src/app/main/data/workspace/drawing.cljs | 2 -- .../src/app/main/data/workspace/texts.cljs | 36 +++++++++---------- .../app/main/data/workspace/transforms.cljs | 1 - frontend/src/app/main/store.cljs | 5 +-- .../app/main/ui/workspace/shapes/text.cljs | 6 ++-- .../main/ui/workspace/shapes/text/editor.cljs | 4 +-- frontend/src/app/util/debug.cljs | 5 +++ 7 files changed, 30 insertions(+), 29 deletions(-) diff --git a/frontend/src/app/main/data/workspace/drawing.cljs b/frontend/src/app/main/data/workspace/drawing.cljs index d83d2b79c..ece9fffba 100644 --- a/frontend/src/app/main/data/workspace/drawing.cljs +++ b/frontend/src/app/main/data/workspace/drawing.cljs @@ -39,8 +39,6 @@ (watch [_ state stream] (let [stoper (rx/filter (ptk/type? ::clear-drawing) stream)] (rx/merge - (rx/of (dws/deselect-all)) - (when (= tool :path) (rx/of (start-drawing :path))) diff --git a/frontend/src/app/main/data/workspace/texts.cljs b/frontend/src/app/main/data/workspace/texts.cljs index ed9b2dc82..3f8a34596 100644 --- a/frontend/src/app/main/data/workspace/texts.cljs +++ b/frontend/src/app/main/data/workspace/texts.cljs @@ -16,7 +16,7 @@ [clojure.walk :as walk] [goog.object :as gobj] [potok.core :as ptk] - [app.common.geom.shapes :as geom] + [app.common.geom.shapes :as gsh] [app.common.attrs :as attrs] [app.main.data.workspace.common :as dwc] [app.main.data.workspace.transforms :as dwt] @@ -218,32 +218,28 @@ (watch [_ state stream] (let [page-id (:current-page-id state) shape (get-in state [:workspace-data :pages-index page-id :objects id]) - {:keys [selrect grow-type overflow-text]} shape + {:keys [selrect grow-type overflow-text]} (gsh/transform-shape shape) {shape-width :width shape-height :height} selrect undo-transaction (get-in state [:workspace-undo :transaction]) - events (when (and (> new-width 0) (> new-height 0)) - (cond - (and overflow-text (not= :fixed grow-type)) - [(update-overflow-text id false)] + events + (cond-> [] + (and overflow-text (not= :fixed grow-type)) + (conj (update-overflow-text id false)) - (and (= :fixed grow-type) (not overflow-text) (> new-height shape-height)) - [(update-overflow-text id true)] + (and (= :fixed grow-type) (not overflow-text) (> new-height shape-height)) + (conj (update-overflow-text id true)) - (and (= :fixed grow-type) overflow-text (<= new-height shape-height)) - [(update-overflow-text id false)] + (and (= :fixed grow-type) overflow-text (<= new-height shape-height)) + (conj (update-overflow-text id false)) - (and (or (not= shape-width new-width) - (not= shape-height new-height)) - (= grow-type :auto-width)) - (when (and (pos? shape-width) - (pos? shape-height)) - [(dwt/update-dimensions [id] :width new-width) - (dwt/update-dimensions [id] :height new-height)]) + (and (or (not= shape-width new-width) (not= shape-height new-height)) + (= grow-type :auto-width)) + (conj (dwt/update-dimensions [id] :width new-width) + (dwt/update-dimensions [id] :height new-height)) - (and (not= shape-height new-height) (= grow-type :auto-height)) - (when (pos? shape-height) - [(dwt/update-dimensions [id] :height new-height)])))] + (and (not= shape-height new-height) (= grow-type :auto-height)) + (conj (dwt/update-dimensions [id] :height new-height)))] (if (not (empty? events)) (rx/concat diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index 44d7658a0..514b59b50 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -488,5 +488,4 @@ (ptk/reify ::update-dimensions ptk/WatchEvent (watch [_ state stream] - #_(prn "??? update-dimensions" ids attr value) (rx/of (dwc/update-shapes ids #(gsh/resize-rect % attr value) {:reg-objects? true}))))) diff --git a/frontend/src/app/main/store.cljs b/frontend/src/app/main/store.cljs index e182969f3..4b06ecce0 100644 --- a/frontend/src/app/main/store.cljs +++ b/frontend/src/app/main/store.cljs @@ -15,7 +15,7 @@ [app.common.pages-helpers :as cph] [app.common.uuid :as uuid] [app.util.storage :refer [storage]] - [app.util.debug :refer [debug? logjs]])) + [app.util.debug :refer [debug? debug-exclude-events logjs]])) (enable-console-print!) @@ -43,7 +43,8 @@ (defonce debug-subscription (->> stream (rx/filter ptk/event?) - (rx/filter (fn [s] (debug? :events))) + (rx/filter (fn [s] (and (debug? :events) + (not (debug-exclude-events (ptk/type s)))))) (rx/subs #(println "[stream]: " (repr-event %)))))) (defn emit! ([] nil) diff --git a/frontend/src/app/main/ui/workspace/shapes/text.cljs b/frontend/src/app/main/ui/workspace/shapes/text.cljs index 656163308..8d612bb42 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text.cljs @@ -48,7 +48,7 @@ (mf/defc text-wrapper {::mf/wrap-props false} [props] - (let [{:keys [id name x y width height] :as shape} (unchecked-get props "shape") + (let [{:keys [id name x y width height grow-type] :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) @@ -79,6 +79,7 @@ (timers/raf #(let [width (obj/get-in entries [0 "contentRect" "width"]) height (obj/get-in entries [0 "contentRect" "height"])] + (log/debug :msg "Resize detected" :shape-id id :width width :height height) (st/emit! (dwt/resize-text id (mth/ceil width) (mth/ceil height)))))))) text-ref-cb @@ -93,7 +94,7 @@ (reset! paragraph-ref ps-node))))))))] (mf/use-effect - (mf/deps @paragraph-ref handle-resize-text) + (mf/deps @paragraph-ref handle-resize-text grow-type) (fn [] (when-let [paragraph-node @paragraph-ref] (let [observer (js/ResizeObserver. handle-resize-text)] @@ -101,6 +102,7 @@ (.observe observer paragraph-node) #(.disconnect observer))))) + [:> shape-container {:shape shape} ;; We keep hidden the shape when we're editing so it keeps track of the size ;; and updates the selrect acordingly diff --git a/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs b/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs index f54187a68..877617358 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs @@ -165,13 +165,13 @@ on-click-outside (fn [event] - (let [sidebar (dom/get-element "settings-bar") + (let [options (dom/get-element-by-class "element-options") assets (dom/get-element-by-class "assets-bar") cpicker (dom/get-element-by-class "colorpicker-tooltip") self (mf/ref-val self-ref) target (dom/get-target event) selecting? (mf/ref-val selecting-ref)] - (when-not (or (and sidebar (.contains sidebar target)) + (when-not (or (and options (.contains options target)) (and assets (.contains assets target)) (and self (.contains self target)) (and cpicker (.contains cpicker target))) diff --git a/frontend/src/app/util/debug.cljs b/frontend/src/app/util/debug.cljs index c562b1b3f..b1787add2 100644 --- a/frontend/src/app/util/debug.cljs +++ b/frontend/src/app/util/debug.cljs @@ -4,6 +4,11 @@ (def debug-options #{:bounding-boxes :group :events :rotation-handler :resize-handler :selection-center #_:simple-selection}) +;; These events are excluded when we activate the :events flag +(def debug-exclude-events + #{:app.main.data.workspace.notifications/handle-pointer-update + :app.main.data.workspace.selection/change-hover-state}) + (defonce ^:dynamic *debug* (atom #{})) (defn debug-all! [] (reset! *debug* debug-options))