mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 08:50:57 -05:00
✨ Improved performance on move and text resize
This commit is contained in:
parent
59187f9ff4
commit
d67dd21c56
3 changed files with 45 additions and 119 deletions
|
@ -1050,30 +1050,13 @@
|
||||||
selected (get-in state [:workspace-local :selected])
|
selected (get-in state [:workspace-local :selected])
|
||||||
moved (if (= 1 (count selected))
|
moved (if (= 1 (count selected))
|
||||||
(align-object-to-frame objects (first selected) axis)
|
(align-object-to-frame objects (first selected) axis)
|
||||||
(align-objects-list objects selected axis))]
|
(align-objects-list objects selected axis))
|
||||||
(loop [moved (seq moved)
|
|
||||||
rchanges []
|
moved-objects (->> moved (group-by :id))
|
||||||
uchanges []]
|
ids (keys moved-objects)
|
||||||
(if (nil? moved)
|
update-fn (fn [shape] (first (get moved-objects (:id shape))))]
|
||||||
(do
|
|
||||||
;; (println "================ rchanges")
|
(rx/of (dch/update-shapes ids update-fn {:reg-objects? true}))))))
|
||||||
;; (cljs.pprint/pprint rchanges)
|
|
||||||
;; (println "================ uchanges")
|
|
||||||
;; (cljs.pprint/pprint uchanges)
|
|
||||||
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true})))
|
|
||||||
(let [curr (first moved)
|
|
||||||
prev (get objects (:id curr))
|
|
||||||
ops1 (dwc/generate-operations prev curr)
|
|
||||||
ops2 (dwc/generate-operations curr prev true)]
|
|
||||||
(recur (next moved)
|
|
||||||
(conj rchanges {:type :mod-obj
|
|
||||||
:page-id page-id
|
|
||||||
:operations ops1
|
|
||||||
:id (:id curr)})
|
|
||||||
(conj uchanges {:type :mod-obj
|
|
||||||
:page-id page-id
|
|
||||||
:operations ops2
|
|
||||||
:id (:id curr)})))))))))
|
|
||||||
|
|
||||||
(defn align-object-to-frame
|
(defn align-object-to-frame
|
||||||
[objects object-id axis]
|
[objects object-id axis]
|
||||||
|
@ -1097,30 +1080,12 @@
|
||||||
objects (dwc/lookup-page-objects state page-id)
|
objects (dwc/lookup-page-objects state page-id)
|
||||||
selected (get-in state [:workspace-local :selected])
|
selected (get-in state [:workspace-local :selected])
|
||||||
moved (-> (map #(get objects %) selected)
|
moved (-> (map #(get objects %) selected)
|
||||||
(gal/distribute-space axis objects))]
|
(gal/distribute-space axis objects))
|
||||||
(loop [moved (seq moved)
|
|
||||||
rchanges []
|
moved-objects (->> moved (group-by :id))
|
||||||
uchanges []]
|
ids (keys moved-objects)
|
||||||
(if (nil? moved)
|
update-fn (fn [shape] (first (get moved-objects (:id shape))))]
|
||||||
(do
|
(rx/of (dch/update-shapes ids update-fn {:reg-objects? true}))))))
|
||||||
;; (println "================ rchanges")
|
|
||||||
;; (cljs.pprint/pprint rchanges)
|
|
||||||
;; (println "================ uchanges")
|
|
||||||
;; (cljs.pprint/pprint uchanges)
|
|
||||||
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true})))
|
|
||||||
(let [curr (first moved)
|
|
||||||
prev (get objects (:id curr))
|
|
||||||
ops1 (dwc/generate-operations prev curr)
|
|
||||||
ops2 (dwc/generate-operations curr prev true)]
|
|
||||||
(recur (next moved)
|
|
||||||
(conj rchanges {:type :mod-obj
|
|
||||||
:page-id page-id
|
|
||||||
:operations ops1
|
|
||||||
:id (:id curr)})
|
|
||||||
(conj uchanges {:type :mod-obj
|
|
||||||
:page-id page-id
|
|
||||||
:operations ops2
|
|
||||||
:id (:id curr)})))))))))
|
|
||||||
|
|
||||||
;; --- Shape Proportions
|
;; --- Shape Proportions
|
||||||
|
|
||||||
|
|
|
@ -220,58 +220,41 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
|
objects (get-in state [:workspace-data :pages-index page-id :objects])]
|
||||||
objects0 (get-in state [:workspace-file :data :pages-index page-id :objects])
|
(if-not (every? #(contains? objects(first %)) changes)
|
||||||
objects1 (get-in state [:workspace-data :pages-index page-id :objects])]
|
|
||||||
(if-not (every? #(contains? objects1(first %)) changes)
|
|
||||||
(rx/empty)
|
(rx/empty)
|
||||||
(let [change-text-shape
|
|
||||||
(fn [objects [id [new-width new-height]]]
|
|
||||||
(when (contains? objects id)
|
|
||||||
(let [shape (get objects id)
|
|
||||||
{:keys [selrect grow-type overflow-text]} (gsh/transform-shape shape)
|
|
||||||
{shape-width :width shape-height :height} selrect
|
|
||||||
|
|
||||||
modifier-width (gsh/resize-modifiers shape :width new-width)
|
(let [changes-map (->> changes (into {}))
|
||||||
modifier-height (gsh/resize-modifiers shape :height new-height)
|
ids (keys changes-map)
|
||||||
|
update-fn
|
||||||
|
(fn [shape]
|
||||||
|
(let [[new-width new-height] (get changes-map (:id shape))
|
||||||
|
{:keys [selrect grow-type overflow-text]} (gsh/transform-shape shape)
|
||||||
|
{shape-width :width shape-height :height} selrect
|
||||||
|
|
||||||
shape (cond-> shape
|
modifier-width (gsh/resize-modifiers shape :width new-width)
|
||||||
(and overflow-text (not= :fixed grow-type))
|
modifier-height (gsh/resize-modifiers shape :height new-height)]
|
||||||
(assoc :overflow-text false)
|
|
||||||
|
|
||||||
(and (= :fixed grow-type) (not overflow-text) (> new-height shape-height))
|
(cond-> shape
|
||||||
(assoc :overflow-text true)
|
(and overflow-text (not= :fixed grow-type))
|
||||||
|
(assoc :overflow-text false)
|
||||||
|
|
||||||
(and (= :fixed grow-type) overflow-text (<= new-height shape-height))
|
(and (= :fixed grow-type) (not overflow-text) (> new-height shape-height))
|
||||||
(assoc :overflow-text false)
|
(assoc :overflow-text true)
|
||||||
|
|
||||||
(and (not-changed? shape-width new-width) (= grow-type :auto-width))
|
(and (= :fixed grow-type) overflow-text (<= new-height shape-height))
|
||||||
(-> (assoc :modifiers modifier-width)
|
(assoc :overflow-text false)
|
||||||
(gsh/transform-shape))
|
|
||||||
|
|
||||||
(and (not-changed? shape-height new-height)
|
(and (not-changed? shape-width new-width) (= grow-type :auto-width))
|
||||||
(or (= grow-type :auto-height) (= grow-type :auto-width)))
|
(-> (assoc :modifiers modifier-width)
|
||||||
(-> (assoc :modifiers modifier-height)
|
(gsh/transform-shape))
|
||||||
(gsh/transform-shape)))]
|
|
||||||
(assoc objects id shape))))
|
|
||||||
|
|
||||||
undo-transaction (get-in state [:workspace-undo :transaction])
|
(and (not-changed? shape-height new-height)
|
||||||
objects2 (->> changes (reduce change-text-shape objects1))
|
(or (= grow-type :auto-height) (= grow-type :auto-width)))
|
||||||
|
(-> (assoc :modifiers modifier-height)
|
||||||
|
(gsh/transform-shape)))))]
|
||||||
|
|
||||||
regchg {:type :reg-objects
|
(rx/of (dch/update-shapes ids update-fn {:reg-objects? true}))))))))
|
||||||
:page-id page-id
|
|
||||||
:shapes (vec (keys changes))}
|
|
||||||
|
|
||||||
rchanges (dwc/generate-changes page-id objects1 objects2)
|
|
||||||
uchanges (dwc/generate-changes page-id objects2 objects0)]
|
|
||||||
|
|
||||||
(if (seq rchanges)
|
|
||||||
(rx/concat
|
|
||||||
(when-not undo-transaction
|
|
||||||
(rx/of (dwc/start-undo-transaction)))
|
|
||||||
(rx/of (dwc/commit-changes (conj rchanges regchg) (conj uchanges regchg) {:commit-local? true}))
|
|
||||||
(when-not undo-transaction
|
|
||||||
(rx/of (dwc/discard-undo-transaction)))))))))))
|
|
||||||
|
|
||||||
;; When a resize-event arrives we start "buffering" for a time
|
;; When a resize-event arrives we start "buffering" for a time
|
||||||
;; after that time we invoke `resize-text-batch` with all the changes
|
;; after that time we invoke `resize-text-batch` with all the changes
|
||||||
|
|
|
@ -454,35 +454,13 @@
|
||||||
(ptk/reify ::apply-modifiers
|
(ptk/reify ::apply-modifiers
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [objects (dwc/lookup-page-objects state)
|
||||||
|
children-ids (->> ids (mapcat #(cp/get-children % objects)))
|
||||||
objects0 (get-in state [:workspace-file :data :pages-index page-id :objects])
|
ids-with-children (d/concat [] children-ids ids)]
|
||||||
objects1 (get-in state [:workspace-data :pages-index page-id :objects])
|
(rx/of (dwu/start-undo-transaction)
|
||||||
|
(dch/update-shapes ids-with-children gsh/transform-shape {:reg-objects? true})
|
||||||
;; ID's + Children ID's
|
|
||||||
ids-with-children (d/concat [] (mapcat #(cp/get-children % objects1) ids) ids)
|
|
||||||
|
|
||||||
;; For each shape applies the modifiers by transforming the objects
|
|
||||||
update-shape #(update %1 %2 gsh/transform-shape)
|
|
||||||
objects2 (reduce update-shape objects1 ids-with-children)
|
|
||||||
|
|
||||||
regchg {:type :reg-objects
|
|
||||||
:page-id page-id
|
|
||||||
:shapes (vec ids)}
|
|
||||||
|
|
||||||
;; we need to generate redo chages from current
|
|
||||||
;; state (with current temporal values) to new state but
|
|
||||||
;; the undo should be calculated from clear current
|
|
||||||
;; state (without temporal values in it, for this reason
|
|
||||||
;; we have 3 different objects references).
|
|
||||||
|
|
||||||
rchanges (conj (dwc/generate-changes page-id objects1 objects2) regchg)
|
|
||||||
uchanges (conj (dwc/generate-changes page-id objects2 objects0) regchg)]
|
|
||||||
|
|
||||||
(rx/of (dwc/start-undo-transaction)
|
|
||||||
(dwc/commit-changes rchanges uchanges {:commit-local? true})
|
|
||||||
(clear-local-transform)
|
(clear-local-transform)
|
||||||
(dwc/commit-undo-transaction))))))
|
(dwu/commit-undo-transaction))))))
|
||||||
|
|
||||||
;; --- Update Dimensions
|
;; --- Update Dimensions
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue