mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 09:42:01 +00:00
🐛 Lay out a resized copy's subtree without its parent's layout
A sync that turns and resizes a copy lays out the copy's main subtree at the copy's size. That layout climbed to the main's parent: in a grid whose duplicated child had no cell yet, laying out the grid crashed. The subtree is laid out under the root, so only its own layouts run and no layout of the main's parent owns the copy's size. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 19.675 | 0.56 | | edit-through-a-chain-of-dependents | 68.931 | 43.856 | 0.64 | | library-update-into-copies | 83.083 | 45.859 | 0.55 | | main-edit-among-many-shapes | 4.837 | 2.118 | 0.44 | | main-edit-into-10-copies | 1.79 | 1.051 | 0.59 | | main-edit-into-100-copies | 15.415 | 9.265 | 0.60 | | main-edit-into-1000-copies | 153.086 | 92.142 | 0.60 | | variant-switch-into-copies | 32.052 | 21.434 | 0.67 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
a7e39ae8cb
commit
2c918644d1
@ -38,6 +38,7 @@
|
||||
[app.common.types.text :as txt]
|
||||
[app.common.types.token :as cto]
|
||||
[app.common.types.typography :as cty]
|
||||
[app.common.uuid :as uuid]
|
||||
[clojure.set :as set]))
|
||||
|
||||
;; Change this to :info :debug or :trace to debug this module, or :warn to reset to default
|
||||
@ -565,9 +566,10 @@
|
||||
objects
|
||||
(let [modif-tree (gm/set-objects-modifiers
|
||||
{(:id shape-main) {:modifiers (ctm/change-size shape-main width height)}}
|
||||
;; the copy keeps its own size, which no layout of the main owns
|
||||
;; the subtree alone, under the root: no layout of the main's
|
||||
;; parent owns the copy's size
|
||||
(-> (reduce-kv #(d/update-when %1 %2 merge %3) objects authored)
|
||||
(assoc-in [(:id shape-main) :layout-item-absolute] true)))]
|
||||
(update (:id shape-main) assoc :parent-id uuid/zero)))]
|
||||
(reduce-kv (fn [objects id {:keys [modifiers]}]
|
||||
(d/update-when objects id gsh/transform-shape modifiers))
|
||||
objects
|
||||
|
||||
@ -1187,3 +1187,13 @@
|
||||
:grid-square false :library true :rich-variants true :layout-children false
|
||||
:grid-empty false :layout-copies true :text true}]
|
||||
:ops [[:nest 6 0 0 0] [:text 6 0 0 0] [:delete 6 0 0 0] [:swap 6 0 0 0] [:switch 0 0 0 0]]}))))
|
||||
|
||||
(t/deftest generated-duplicate-in-a-grid-resizes-a-copy-subtree-alone
|
||||
;; a sync that resizes a copy in a grid lays out the copy's subtree while
|
||||
;; the grid has a duplicated child with no cell yet; the program reaches
|
||||
;; that sync on every other run, so it runs twice
|
||||
(dotimes [_ 2]
|
||||
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout :grid :variant-diff false
|
||||
:layout-item-margins false :grid-square false :rich-variants true
|
||||
:layout-children false :grid-empty true :layout-copies true :text true}]
|
||||
:ops [[:style 0 29 1] [:nest 9 0 0 0] [:duplicate 5 1 0 0]]})))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user