mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Keep the layout item overrides of a switched copy head
A swap gives the new head the layout item values of the head it replaces, without touching it. A variant switch then carries the old head's overrides, but skips any attribute that already has the old value, so the kept layout item values lost the overrides that authored them: a later sync of a copy could replace them, and reset no longer saw them. A switch also gives the new head the touched groups of the kept attributes the old head had. The model expects the old head's layout item overrides to survive a switch. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 18.466 | 0.52 | | edit-through-a-chain-of-dependents | 68.931 | 38.447 | 0.56 | | library-update-into-copies | 83.083 | 45.429 | 0.55 | | main-edit-among-many-shapes | 4.837 | 2.162 | 0.45 | | main-edit-into-10-copies | 1.79 | 1.064 | 0.59 | | main-edit-into-100-copies | 15.415 | 9.072 | 0.59 | | main-edit-into-1000-copies | 153.086 | 89.75 | 0.59 | | variant-switch-into-copies | 32.052 | 19.484 | 0.61 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
8f0b749563
commit
ae0326d63f
@ -617,6 +617,20 @@
|
||||
(pcb/update-shapes [(:id shape)] #(update % :touched ctk/set-touched-group :geometry-group)
|
||||
{:ignore-touched true}))))
|
||||
|
||||
(defn- keep-placement-overrides
|
||||
"A switch gives the new head the `swap-keep-attrs` of the copy head
|
||||
`original-shape` it replaces, and with them the overrides that authored
|
||||
them."
|
||||
[changes original-shape new-shape]
|
||||
(let [groups (into #{}
|
||||
(comp (keep #(ctk/resolve-sync-group (:type original-shape) %))
|
||||
(filter #(ctk/touched-group? original-shape %)))
|
||||
ctk/swap-keep-attrs)]
|
||||
(cond-> changes
|
||||
(seq groups)
|
||||
(pcb/update-shapes [(:id new-shape)] #(update % :touched (fnil into #{}) groups)
|
||||
{:ignore-touched true}))))
|
||||
|
||||
(defn generate-component-swap-in-place
|
||||
"Swap the copy head `shape` of `page` for a copy of the component
|
||||
`component-id` of library data `ldata`. The new head takes the old one's
|
||||
@ -650,7 +664,8 @@
|
||||
|
||||
changes (cond-> changes
|
||||
keep-touched?
|
||||
(keep-moved-placement shape new-shape page libraries))
|
||||
(-> (keep-moved-placement shape new-shape page libraries)
|
||||
(keep-placement-overrides shape new-shape)))
|
||||
|
||||
;; Replacement keeps the head id and its cell. Cleanup during the
|
||||
;; temporary deletion must not change the parent's placement data.
|
||||
|
||||
@ -1093,3 +1093,10 @@
|
||||
:ops [[:edit 18 0 0 0] [:delete 0 0 0 0] [:edit 3 0 1 1] [:update-main 3] [:update-main 0 0 0 0]
|
||||
[:resize 6 0 0 0] [:nest 16 0 0 0] [:swap 16 0 0 0] [:detach 2 0 0 0] [:style 8 20 2 0]
|
||||
[:reset 13 0 0 0]]}))))
|
||||
|
||||
(t/deftest generated-switch-keeps-the-layout-item-override-it-carries
|
||||
;; a nested copy in a main with its own layout item margin keeps the
|
||||
;; margin through a switch, and the override that authors it
|
||||
(t/is (map? (cg/run {:world [3 2 {:variants true :text-styles true :layout :flex :variant-diff false :rich-variants true
|
||||
:layout-children true :layout-copies true :text true}]
|
||||
:ops [[:delete 6 0 0 0] [:swap 20 0 0 0] [:nest 7 0 0 0] [:style 13 27 1] [:switch 0 0 0 0]]}))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user