mirror of
https://github.com/penpot/penpot.git
synced 2026-08-29 08:08:46 +00:00
⚡ Defer stale text selrect sync until viewport is ready
Coalesce stale-selrect ids and emit after the first tiles-complete pass, scheduled on idle, so the page can paint before resize work.
This commit is contained in:
parent
666f43b4ad
commit
627921cb46
@ -1653,6 +1653,33 @@
|
||||
:auto-height (not (mth/close? height (:height selrect) 0.1))
|
||||
false)))
|
||||
|
||||
(defonce ^:private pending-stale-selrect-ids (atom #{}))
|
||||
(defonce ^:private stale-selrect-sync-token (atom 0))
|
||||
|
||||
(defn- flush-stale-selrect-sync!
|
||||
[]
|
||||
(let [ids (swap! pending-stale-selrect-ids
|
||||
(fn [pending]
|
||||
(reset! pending-stale-selrect-ids #{})
|
||||
pending))]
|
||||
(when (seq ids)
|
||||
(st/emit! (ptk/data-event ::stale-text-selrects {:ids (vec ids)})))))
|
||||
|
||||
(defn- schedule-stale-selrect-sync!
|
||||
"Coalesce stale-selrect emissions and defer until the first viewport tile
|
||||
pass completes, then run on idle so page load can paint first."
|
||||
[stale-ids]
|
||||
(swap! pending-stale-selrect-ids into stale-ids)
|
||||
(let [token (swap! stale-selrect-sync-token inc)
|
||||
flush-on-idle!
|
||||
(fn []
|
||||
(when (= token @stale-selrect-sync-token)
|
||||
(timers/schedule-on-idle
|
||||
(fn []
|
||||
(when (= token @stale-selrect-sync-token)
|
||||
(flush-stale-selrect-sync!))))))]
|
||||
(listen-tiles-render-complete-once! flush-on-idle!)))
|
||||
|
||||
(defn- sync-stale-text-selrects!
|
||||
"Emit the ids of auto-grow text shapes whose selrect no longer matches the
|
||||
measured layout, so the workspace resizes them (data-event instead of a
|
||||
@ -1666,7 +1693,7 @@
|
||||
(map :id))
|
||||
shapes)]
|
||||
(when (seq stale-ids)
|
||||
(st/emit! (ptk/data-event ::stale-text-selrects {:ids stale-ids})))))
|
||||
(schedule-stale-selrect-sync! stale-ids))))
|
||||
|
||||
(defn- relayout-after-fonts!
|
||||
"Relayout text shapes once their pending fonts have resolved. Font fetches
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user