mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 17:50:38 +00:00
🐛 Carry no override of a swap a main makes across a switch
A main that nests a variant copy can swap a child of it for another component and override that component's fill. A copy of the main that switched its nested copy took the touched groups of the child's whole ref chain and compared them with the variant's slot, so it carried the fill authored over the swapped component onto the new variant's board. A child whose ref chain passes through a swap made by a main now has no counterpart in the new variant, and nothing carries into it. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+---------+--------+--------| | deepest-edit-through-three-levels | 35.215 | 19.723 | 20.106 | 0.56 | | edit-through-a-chain-of-dependents | 68.931 | 36.982 | 39.628 | 0.54 | | library-update-into-copies | 83.083 | 44.331 | 46.283 | 0.53 | | main-edit-among-many-shapes | 4.837 | 1.969 | 2.159 | 0.41 | | main-edit-into-10-copies | 1.79 | 1.05 | 1.078 | 0.59 | | main-edit-into-100-copies | 15.415 | 10.02 | 10.27 | 0.65 | | main-edit-into-1000-copies | 153.086 | 100.392 | 102.54 | 0.66 | | variant-switch-into-copies | 32.052 | 19.796 | 20.354 | 0.62 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
ce5c425251
commit
9a52566167
@ -507,9 +507,18 @@
|
||||
orig-base-ref-shape
|
||||
(find-shape-ref-child-of container libraries old (:id orig-base-ref-shape)))
|
||||
new (get new-shapes-map (get o-ref-shapes-p-map (:id old-ref)))
|
||||
swapped? (and (not root?) (ctk/swapped? old))]
|
||||
swapped? (and (not root?) (ctk/swapped? old))
|
||||
;; a main between the shape and the variant swapped it, so its
|
||||
;; content and overrides belong to another component
|
||||
swapped-in-chain?
|
||||
(and (not root?) (not swapped?)
|
||||
(some #(and (ctk/swapped? %) (not= (:id %) (:id old-ref)))
|
||||
(rest (ctf/get-ref-chain-until-target-ref container libraries old
|
||||
(:id old-ref)))))]
|
||||
;; a swap is kept only where the new variant holds a copy
|
||||
(when (and new (or (not swapped?) (ctk/instance-head? new)))
|
||||
(when (and new
|
||||
(not swapped-in-chain?)
|
||||
(or (not swapped?) (ctk/instance-head? new)))
|
||||
{:old old :old-ref old-ref :new new :swapped? swapped?})))
|
||||
orig-touched)
|
||||
|
||||
|
||||
@ -1857,6 +1857,13 @@
|
||||
[:make-variant 0 0 0 0] [:detach 0 0 0 0] [:variant-property 0 0 0 0]
|
||||
[:switch 12]]}))))
|
||||
|
||||
(t/deftest switching-a-copy-carries-no-override-of-a-swap-its-main-makes
|
||||
(t/is (map? (cg/run {:world [3 2 {:variants true :text-styles true :layout nil :variant-diff false
|
||||
:layout-item-margins false :grid-square false :rich-variants true
|
||||
:layout-children false :grid-empty false :layout-copies true :text true}]
|
||||
:ops [[:edit 3 0 0 1] [:variant-property 0 6 0 0] [:switch 0] [:make-variant 5]
|
||||
[:switch 13] [:make-variant 13 0 0 0] [:add-variant 0] [:switch 10]]}))))
|
||||
|
||||
(t/deftest random-variant-compositions
|
||||
(let [coverage (atom {})
|
||||
failure (atom nil)]
|
||||
|
||||
@ -3573,6 +3573,32 @@
|
||||
(t/is (gpt/close? (offset-in-root file :m02 :m02-icon)
|
||||
(offset-in-root file' :copy02 :copy-icon-b)))))
|
||||
|
||||
(t/deftest test-switch-carries-no-override-of-a-swap-its-main-makes
|
||||
(let [;; ==== Setup: a main nests a copy of the first variant, swaps its icon
|
||||
;; for icon B and fills it; a copy of that main holds the nested copy
|
||||
red [{:fill-color "#ff0000" :fill-opacity 1}]
|
||||
file (-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component :icon-a :icon-a-root :icon-a-child)
|
||||
(tho/add-simple-component :icon-b :icon-b-root :icon-b-child)
|
||||
(thv/add-variant-with-copy :v01 :c01 :m01 :c02 :m02 :m01-icon :m02-icon :icon-a)
|
||||
(tho/add-frame :outer-root)
|
||||
(thc/instantiate-component :c01 :nested :parent-label :outer-root
|
||||
:children-labels [:nested-icon])
|
||||
(thc/component-swap :nested-icon :icon-b :nested-icon-b)
|
||||
(tho/change-shape :nested-icon-b #(assoc % :fills red))
|
||||
(thc/make-component :outer :outer-root)
|
||||
(thc/instantiate-component :outer :copy-outer :children-labels [:copy-nested]))
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component-in-shape file :copy-nested :c02 {:new-shape-label :copy-nested-2
|
||||
:keep-touched? true})
|
||||
icon' (ths/get-shape-by-id file' (-> (ths/get-shape file' :copy-nested-2) :shapes first))]
|
||||
|
||||
;; ==== Check: the fill is icon B's override, which icon A does not take
|
||||
(t/is (contains? (:touched (ths/get-shape file :nested-icon-b)) :fill-group))
|
||||
(t/is (not (contains? (:touched icon') :fill-group)))
|
||||
(t/is (= (:fills (ths/get-shape file' :m02-icon)) (:fills icon')))))
|
||||
|
||||
(t/deftest test-switch-drops-a-swap-the-new-variant-holds-no-copy-for
|
||||
(let [;; ==== Setup: the second variant's icon is detached into a plain board
|
||||
file (setup-variant-with-swapped-icon)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user