From cd151db5eea4df13b9cda914916460f83fbf5c38 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 22 Sep 2020 16:08:08 +0200 Subject: [PATCH] :bug: Fixed problem with zoom and with value = 0 --- common/app/common/geom/shapes.cljc | 5 +++-- frontend/src/app/main/data/workspace.cljs | 4 ++-- frontend/src/app/main/data/workspace/common.cljs | 9 +++++---- .../src/app/main/data/workspace/drawing.cljs | 9 +++++++-- .../src/app/main/ui/workspace/shapes/text.cljs | 16 +++++++++++----- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/common/app/common/geom/shapes.cljc b/common/app/common/geom/shapes.cljc index de18537fc..399999cef 100644 --- a/common/app/common/geom/shapes.cljc +++ b/common/app/common/geom/shapes.cljc @@ -660,17 +660,18 @@ ;; Normalize x/y vector coordinates because scale by 0 is infinite res-x (cond (and (< res-x 0) (> res-x -0.01)) -0.01 - (and (> res-x 0) (< res-x 0.01)) 0.01 + (and (>= res-x 0) (< res-x 0.01)) 0.01 :else res-x) res-y (cond (and (< res-y 0) (> res-y -0.01)) -0.01 - (and (> res-y 0) (< res-y 0.01)) 0.01 + (and (>= res-y 0) (< res-y 0.01)) 0.01 :else res-y) resize (gpt/point res-x res-y) origin (:resize-origin modifiers (gpt/point 0 0)) + resize-transform (:resize-transform modifiers (gmt/matrix)) resize-transform-inverse (:resize-transform-inverse modifiers (gmt/matrix)) rt-modif (:rotation modifiers 0) diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 90a5d2091..d5fc8e8d1 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1289,7 +1289,7 @@ (watch [_ state stream] (let [id (uuid/next) {:keys [x y]} @ms/mouse-position - width (* 7 (count text)) + width (min (* 7 (count text)) 700) height 16 shape {:id id :type :text @@ -1304,7 +1304,7 @@ :height height} :width width :height height - :grow-type :auto-width + :grow-type (if (> (count text) 100) :auto-height :auto-width) :content (as-content text)}] (rx/of dwc/start-undo-transaction dws/deselect-all diff --git a/frontend/src/app/main/data/workspace/common.cljs b/frontend/src/app/main/data/workspace/common.cljs index d73b48956..1b4387d34 100644 --- a/frontend/src/app/main/data/workspace/common.cljs +++ b/frontend/src/app/main/data/workspace/common.cljs @@ -302,10 +302,11 @@ ptk/UpdateEvent (update [_ state] ;; We commit the old transaction before starting the new one - (-> state - (add-undo-entry (get-in state [:workspace-undo :transaction])) - (assoc-in [:workspace-undo :transaction] {:undo-changes [] - :redo-changes []}))))) + (let [empty-tx {:undo-changes [] :redo-changes []} + current-tx (get-in state [:workspace-undo :transaction])] + (cond-> state + (nil? current-tx) (assoc-in [:workspace-undo :transaction] empty-tx)))))) + (def discard-undo-transaction (ptk/reify ::discard-undo-transaction ptk/UpdateEvent diff --git a/frontend/src/app/main/data/workspace/drawing.cljs b/frontend/src/app/main/data/workspace/drawing.cljs index c0878ff9a..c61420901 100644 --- a/frontend/src/app/main/data/workspace/drawing.cljs +++ b/frontend/src/app/main/data/workspace/drawing.cljs @@ -294,8 +294,13 @@ geom/transform-shape (dissoc ::initialized? ::click-draw?))] ;; Add & select the created shape to the workspace - (rx/of dw/deselect-all - (dw/add-shape shape))))))))) + (rx/concat + (if (= :text (:type shape)) + (rx/of dwc/start-undo-transaction) + (rx/empty)) + + (rx/of dw/deselect-all + (dw/add-shape shape)))))))))) (def close-drawing-path (ptk/reify ::close-drawing-path diff --git a/frontend/src/app/main/ui/workspace/shapes/text.cljs b/frontend/src/app/main/ui/workspace/shapes/text.cljs index f3faf51eb..f9c27795b 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text.cljs @@ -57,6 +57,7 @@ selected (mf/deref refs/selected-shapes) edition (mf/deref refs/selected-edition) + zoom (mf/deref refs/selected-zoom) edition? (= edition id) selected? (and (contains? selected id) (= (count selected) 1)) @@ -80,10 +81,12 @@ :style {:pointer-events "none"}} ;; We only render the component for its side-effect [:& text-shape-edit {:shape shape + :zoom zoom :read-only? true}]]) (if edition? - [:& text-shape-edit {:shape shape}] + [:& text-shape-edit {:shape shape + :zoom zoom}] [:& text/text-shape {:shape shape :selected? selected?}])]])) @@ -258,7 +261,7 @@ (mf/defc text-shape-edit {::mf/wrap [mf/memo]} - [{:keys [shape read-only?] :or {read-only? false} :as props}] + [{:keys [shape zoom read-only?] :or {read-only? false} :as props}] (let [{:keys [id x y width height content grow-type]} shape state (mf/use-state #(parse-content content)) @@ -349,15 +352,18 @@ ;; Checks the size of the wrapper to update if it were necesary (mf/use-effect - (mf/deps props @loaded-fonts) + (mf/deps shape @loaded-fonts) (fn [] (timers/schedule 250 ;; We need to wait to the text to be rendered. Is there a better alternative? #(let [self-node (mf/ref-val self-ref) paragraph-node (when self-node (dom/query self-node ".paragraph-set"))] (when paragraph-node - (let [{:keys [width height]} (dom/get-bounding-rect paragraph-node) - undo-transaction (get-in @st/state [:workspaceundo :transaction])] + (let [ + {bb-w :width bb-h :height} (dom/get-bounding-rect paragraph-node) + width (max (/ bb-w zoom) 7) + height (max (/ bb-h zoom) 16) + undo-transaction (get-in @st/state [:workspace-undo :transaction])] (when (not undo-transaction) (st/emit! dwc/start-undo-transaction)) (when (or (not= (:width shape) width) (not= (:height shape) height))