mirror of
https://github.com/penpot/penpot.git
synced 2025-01-22 06:32:38 -05:00
🐛 Fixed issues when changing pages quickly while resizing texts
This commit is contained in:
parent
bb04181abf
commit
bc3275e624
1 changed files with 62 additions and 50 deletions
|
@ -228,11 +228,12 @@
|
|||
(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])
|
||||
|
||||
change-text-shape
|
||||
objects1 (get-in state [:workspace-data :pages-index page-id :objects])]
|
||||
(if-not (every? #(contains? objects1(first %)) changes)
|
||||
(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
|
||||
|
@ -258,7 +259,7 @@
|
|||
(or (= grow-type :auto-height) (= grow-type :auto-width)))
|
||||
(-> (assoc :modifiers modifier-height)
|
||||
(gsh/transform-shape)))]
|
||||
(assoc objects id shape)))
|
||||
(assoc objects id shape))))
|
||||
|
||||
undo-transaction (get-in state [:workspace-undo :transaction])
|
||||
objects2 (->> changes (reduce change-text-shape objects1))
|
||||
|
@ -276,7 +277,7 @@
|
|||
(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 (dwc/discard-undo-transaction)))))))))))
|
||||
|
||||
;; When a resize-event arrives we start "buffering" for a time
|
||||
;; after that time we invoke `resize-text-batch` with all the changes
|
||||
|
@ -292,16 +293,16 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [;; This stream aggregates the events of "resizing"
|
||||
resize-events (rx/merge
|
||||
resize-events
|
||||
(rx/merge
|
||||
(->> (rx/of (resize-text id new-width new-height)))
|
||||
(->> stream (rx/filter (ptk/type? ::resize-text))))
|
||||
|
||||
;; Stop buffering after time without resizes
|
||||
stop-buffer (->> resize-events (rx/debounce 100))]
|
||||
stop-buffer (->> resize-events (rx/debounce 100))
|
||||
|
||||
(if-not (::handling-texts state)
|
||||
(->> (rx/concat
|
||||
(rx/of #(assoc % ::handling-texts true))
|
||||
;; Agregates the resizes so only send the resize when the sizes are stable
|
||||
resize-batch
|
||||
(->> resize-events
|
||||
(rx/take-until stop-buffer)
|
||||
(rx/reduce (fn [acc event]
|
||||
|
@ -309,5 +310,16 @@
|
|||
{id [new-width new-height]})
|
||||
(rx/map #(resize-text-batch %)))
|
||||
|
||||
;; This stream retrieves the changes of page so we cancel the agregation
|
||||
change-page
|
||||
(->> stream
|
||||
(rx/filter (ptk/type? :app.main.data.workspace/finalize-page))
|
||||
(rx/take 1)
|
||||
(rx/ignore))]
|
||||
|
||||
(if-not (::handling-texts state)
|
||||
(->> (rx/concat
|
||||
(rx/of #(assoc % ::handling-texts true))
|
||||
(rx/race resize-batch change-page)
|
||||
(rx/of #(dissoc % ::handling-texts))))
|
||||
(rx/empty))))))
|
||||
|
|
Loading…
Add table
Reference in a new issue