0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-12 15:01:28 -05:00

🐛 Fixed problem with zoom and with value = 0

This commit is contained in:
alonso.torres 2020-09-22 16:08:08 +02:00 committed by Andrey Antukh
parent d17c6d8fce
commit cd151db5ee
5 changed files with 28 additions and 15 deletions

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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))