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])
|
||||
moved (if (= 1 (count selected))
|
||||
(align-object-to-frame objects (first selected) axis)
|
||||
(align-objects-list objects selected axis))]
|
||||
(loop [moved (seq moved)
|
||||
rchanges []
|
||||
uchanges []]
|
||||
(if (nil? moved)
|
||||
(do
|
||||
;; (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)})))))))))
|
||||
(align-objects-list objects selected axis))
|
||||
|
||||
moved-objects (->> moved (group-by :id))
|
||||
ids (keys moved-objects)
|
||||
update-fn (fn [shape] (first (get moved-objects (:id shape))))]
|
||||
|
||||
(rx/of (dch/update-shapes ids update-fn {:reg-objects? true}))))))
|
||||
|
||||
(defn align-object-to-frame
|
||||
[objects object-id axis]
|
||||
|
@ -1097,30 +1080,12 @@
|
|||
objects (dwc/lookup-page-objects state page-id)
|
||||
selected (get-in state [:workspace-local :selected])
|
||||
moved (-> (map #(get objects %) selected)
|
||||
(gal/distribute-space axis objects))]
|
||||
(loop [moved (seq moved)
|
||||
rchanges []
|
||||
uchanges []]
|
||||
(if (nil? moved)
|
||||
(do
|
||||
;; (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)})))))))))
|
||||
(gal/distribute-space axis objects))
|
||||
|
||||
moved-objects (->> moved (group-by :id))
|
||||
ids (keys moved-objects)
|
||||
update-fn (fn [shape] (first (get moved-objects (:id shape))))]
|
||||
(rx/of (dch/update-shapes ids update-fn {:reg-objects? true}))))))
|
||||
|
||||
;; --- Shape Proportions
|
||||
|
||||
|
|
|
@ -220,22 +220,22 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [page-id (:current-page-id state)
|
||||
|
||||
objects0 (get-in state [:workspace-file :data :pages-index page-id :objects])
|
||||
objects1 (get-in state [:workspace-data :pages-index page-id :objects])]
|
||||
(if-not (every? #(contains? objects1(first %)) changes)
|
||||
objects (get-in state [:workspace-data :pages-index page-id :objects])]
|
||||
(if-not (every? #(contains? objects(first %)) changes)
|
||||
(rx/empty)
|
||||
(let [change-text-shape
|
||||
(fn [objects [id [new-width new-height]]]
|
||||
(when (contains? objects id)
|
||||
(let [shape (get objects id)
|
||||
|
||||
(let [changes-map (->> changes (into {}))
|
||||
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
|
||||
|
||||
modifier-width (gsh/resize-modifiers shape :width new-width)
|
||||
modifier-height (gsh/resize-modifiers shape :height new-height)
|
||||
modifier-height (gsh/resize-modifiers shape :height new-height)]
|
||||
|
||||
shape (cond-> shape
|
||||
(cond-> shape
|
||||
(and overflow-text (not= :fixed grow-type))
|
||||
(assoc :overflow-text false)
|
||||
|
||||
|
@ -252,26 +252,9 @@
|
|||
(and (not-changed? shape-height new-height)
|
||||
(or (= grow-type :auto-height) (= grow-type :auto-width)))
|
||||
(-> (assoc :modifiers modifier-height)
|
||||
(gsh/transform-shape)))]
|
||||
(assoc objects id shape))))
|
||||
(gsh/transform-shape)))))]
|
||||
|
||||
undo-transaction (get-in state [:workspace-undo :transaction])
|
||||
objects2 (->> changes (reduce change-text-shape objects1))
|
||||
|
||||
regchg {:type :reg-objects
|
||||
: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)))))))))))
|
||||
(rx/of (dch/update-shapes ids update-fn {:reg-objects? true}))))))))
|
||||
|
||||
;; When a resize-event arrives we start "buffering" for a time
|
||||
;; after that time we invoke `resize-text-batch` with all the changes
|
||||
|
|
|
@ -454,35 +454,13 @@
|
|||
(ptk/reify ::apply-modifiers
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [page-id (:current-page-id state)
|
||||
|
||||
objects0 (get-in state [:workspace-file :data :pages-index page-id :objects])
|
||||
objects1 (get-in state [:workspace-data :pages-index page-id :objects])
|
||||
|
||||
;; 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})
|
||||
(let [objects (dwc/lookup-page-objects state)
|
||||
children-ids (->> ids (mapcat #(cp/get-children % objects)))
|
||||
ids-with-children (d/concat [] children-ids ids)]
|
||||
(rx/of (dwu/start-undo-transaction)
|
||||
(dch/update-shapes ids-with-children gsh/transform-shape {:reg-objects? true})
|
||||
(clear-local-transform)
|
||||
(dwc/commit-undo-transaction))))))
|
||||
(dwu/commit-undo-transaction))))))
|
||||
|
||||
;; --- Update Dimensions
|
||||
|
||||
|
|
Loading…
Reference in a new issue