mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Sync a switched copy whose child's swap the switch ends
A switch keeps a child the copy swapped for another component, and when the new variant holds that same component at the child's place the swap ends: the child becomes a plain copy of its new position. It kept the values it had, though, untouched, so it showed its old size or opacity where its new main authored others, until some later sync. When a switch ends a kept child's swap, the switched copy now syncs as an ordinary copy, as it already did when it carries a size. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 20.516 | 0.58 | | edit-through-a-chain-of-dependents | 68.931 | 40.411 | 0.59 | | library-update-into-copies | 83.083 | 52.359 | 0.63 | | main-edit-among-many-shapes | 4.837 | 2.024 | 0.42 | | main-edit-into-10-copies | 1.790 | 0.954 | 0.53 | | main-edit-into-100-copies | 15.415 | 9.210 | 0.60 | | main-edit-into-1000-copies | 153.086 | 91.498 | 0.60 | | variant-switch-into-copies | 32.052 | 19.466 | 0.61 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
85aca392b6
commit
4cf38cfad1
@ -568,10 +568,14 @@
|
||||
:include-deleted? true :with-context? true))
|
||||
changes (keep-orientation-override changes original-shape new-shape page
|
||||
new-ldata (:component-id new-shape) position)
|
||||
;; A carried size changes the frame its untouched children follow.
|
||||
;; Place them through the same constraints as an ordinary copy sync.
|
||||
;; A kept child whose swap ended is a plain copy of its new position
|
||||
ended-swap? (some (fn [{:keys [old swapped?]}]
|
||||
(and swapped? (not (ctk/swapped? (get (pcb/get-objects changes) (:id old))))))
|
||||
pairs)
|
||||
;; A carried size changes the frame its untouched children follow,
|
||||
;; and an ended swap shows its position: both sync as an ordinary copy.
|
||||
changes (cond-> changes
|
||||
(some #(ctk/touched-group? % :geometry-group) orig-touched)
|
||||
(or ended-swap? (some #(ctk/touched-group? % :geometry-group) orig-touched))
|
||||
(cll/generate-sync-shape-direct
|
||||
nil libraries (assoc container :objects (pcb/get-objects changes))
|
||||
(:id new-shape) false))
|
||||
|
||||
@ -1792,6 +1792,14 @@
|
||||
:ops [[:grid-cell 1 0 0 0] [:delete 5 0 0 0] [:make-variant 4 0 0 0]
|
||||
[:variant-property 0 0 0 0] [:switch 9]]}))))
|
||||
|
||||
(t/deftest a-swap-a-switch-ends-shows-its-new-position
|
||||
(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
|
||||
:layout-children false :grid-empty false :layout-copies true :text true}]
|
||||
:ops [[:swap 8 0 0 0] [:resize 0 0 0 0] [:make-variant 7] [:switch 6]
|
||||
[:combine 13 0 0 0] [:variant-property 0 0 0 0] [:switch 13] [:make-variant 0]
|
||||
[:switch 0] [:make-variant 2 0 0 0] [:make-variant 0] [:switch 16]]}))))
|
||||
|
||||
(t/deftest random-variant-compositions
|
||||
(let [coverage (atom {})
|
||||
failure (atom nil)]
|
||||
|
||||
@ -431,6 +431,18 @@
|
||||
(t/is (not (ctk/swapped? head)))
|
||||
(t/is (= (:id (thc/get-component file :heart)) (:component-id head)))))
|
||||
|
||||
(t/deftest switch-to-a-variant-with-the-same-component-takes-its-values
|
||||
;; the ended swap makes the head a plain copy of its new position, so it
|
||||
;; shows what the main authored there
|
||||
(let [file (-> (setup-variants)
|
||||
(tho/swap-component-in-shape :child2 :heart)
|
||||
(set-opacity :child2 0.3)
|
||||
(tho/swap-component-in-shape :copy01 :c02 {:keep-touched? true}))
|
||||
head (ths/get-shape file :copy-child)]
|
||||
(t/is (= (thi/id :child2) (:shape-ref head)))
|
||||
(t/is (= 0.3 (:opacity head)))
|
||||
(t/is (not (ctk/touched-group? head :layer-effects-group)))))
|
||||
|
||||
(t/deftest switch-to-a-variant-with-the-same-component-refers-to-its-children
|
||||
(let [file (-> (setup-variants)
|
||||
(tho/swap-component-in-shape :child2 :heart)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user