mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Place a pushed swap's children like the position it now copies
When update-main pushes a swap into a nested copy in the main, and the position there holds the same component, the pushed head becomes a plain copy of that position. Its content differences become overrides while its placement follows the position, but its descendants kept the places of the pushed copy with no geometry override, so a later sync would move them. They now take the places the position gives them, except the subtrees that author their own geometry. Generated regression: an eleven-step add-variant, switch and update-main program that failed I4 (seed 256567394, round 8) now passes, as does the original program. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+---------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 23.622 | 27.685 | 0.67 | | edit-through-a-chain-of-dependents | 68.931 | 48.952 | 50.286 | 0.71 | | library-update-into-copies | 83.083 | 54.647 | 59.195 | 0.66 | | main-edit-among-many-shapes | 4.837 | 3.23 | 3.376 | 0.67 | | main-edit-into-10-copies | 1.79 | 1.152 | 1.196 | 0.64 | | main-edit-into-100-copies | 15.415 | 11.605 | 11.945 | 0.75 | | main-edit-into-1000-copies | 153.086 | 110.919 | 114.366 | 0.72 | | variant-switch-into-copies | 32.052 | 24.905 | 26.59 | 0.78 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
8161f15015
commit
2311841cf5
@ -1292,13 +1292,33 @@
|
||||
take-position (ctf/take-position nil libraries objects new-head (:shape-ref replaced) position)
|
||||
position-objects (get-in (meta position) [:container :objects])
|
||||
;; the head takes the place the replaced child authored
|
||||
placement (set/intersection (set (:touched replaced)) placement-groups)]
|
||||
placement (set/intersection (set (:touched replaced)) placement-groups)
|
||||
positioned (mapv take-position new-shapes)
|
||||
by-id (d/index-by :id positioned)
|
||||
head (get by-id (:id new-head))
|
||||
;; the position's subtree placed like a head that is a plain copy of it
|
||||
placed (when (and position (not (ctk/swapped? head)))
|
||||
(placed-like position-objects position head
|
||||
(authored-constraints by-id (cfh/get-children-ids by-id (:id head)))))
|
||||
;; the shapes that keep their pushed geometry: the head and the subtrees of those that author theirs
|
||||
kept-ids (into #{(:id head)}
|
||||
(comp (filter #(ctk/touched-group? % :geometry-group))
|
||||
(mapcat #(cfh/get-children-ids-with-self by-id (:id %))))
|
||||
positioned)
|
||||
follow-position (fn [shape]
|
||||
(let [expected (get placed (:shape-ref shape))]
|
||||
(if (and expected
|
||||
(not (contains? kept-ids (:id shape)))
|
||||
(= (:type shape) (:type expected)))
|
||||
(merge shape (select-keys expected (cond-> placement-geometry-attrs
|
||||
(= :path (:type shape)) (conj :content))))
|
||||
shape)))]
|
||||
(mapv (fn [shape]
|
||||
(let [shape (cond-> (take-position shape)
|
||||
(let [shape (cond-> (follow-position shape)
|
||||
(and (= (:id shape) (:id new-head)) (seq placement))
|
||||
(update :touched (fnil into #{}) placement))]
|
||||
(author-pushed-content shape (get position-objects (:shape-ref shape)))))
|
||||
new-shapes))
|
||||
positioned))
|
||||
new-shapes)
|
||||
|
||||
;; the link of a copy shape with its main
|
||||
|
||||
@ -2095,6 +2095,14 @@
|
||||
:ops [[:detach 2] [:switch 8] [:text 4] [:switch] [:nest 2] [:rotate] [:switch]
|
||||
[:combine] [:switch 2]]}))))
|
||||
|
||||
(t/deftest updating-a-main-with-a-swap-to-its-position-component-places-its-children-like-the-position
|
||||
(t/is (map? (cg/run {:world [1 2 {:variants true :text-styles false :layout :flex :variant-diff false
|
||||
:layout-item-margins false :grid-square false :rich-variants true
|
||||
:layout-children false :grid-empty false :layout-copies false :text false}]
|
||||
:ops [[:delete] [:add-variant] [:make-variant 1] [:switch 19] [:style 18 29]
|
||||
[:add-variant] [:add-variant] [:add-variant] [:switch 4] [:transform 0 0 0 7]
|
||||
[:update-main 22]]}))))
|
||||
|
||||
(t/deftest turning-a-flipped-copy-turns-a-child-stored-as-the-other-mirror-turn
|
||||
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false
|
||||
:layout-item-margins false :grid-square false :rich-variants true
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user