0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-12 07:41:43 -05:00

🐛 Fixes some issues with text shape

This commit is contained in:
alonso.torres 2020-12-04 17:35:13 +01:00 committed by Alonso Torres
parent 62d98ad265
commit d0306ac92c
7 changed files with 30 additions and 29 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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