mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Keep the moved place of a copy child a switch replaces as its own
A copy child of a copy can be moved, which marks its geometry as its own. Switching it to another variant keeps the place it was moved to, but the new head only has the swap override, so the next sync brought it back to the place its position in the main gives it. When the switch keeps a first corner that the head's position would not give it inside its copy parent, the new head's geometry is marked as its own. The model expects that place as authored. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 18.478 | 0.52 | | edit-through-a-chain-of-dependents | 68.931 | 37.022 | 0.54 | | library-update-into-copies | 83.083 | 45.307 | 0.55 | | main-edit-among-many-shapes | 4.837 | 2.118 | 0.44 | | main-edit-into-10-copies | 1.79 | 0.975 | 0.54 | | main-edit-into-100-copies | 15.415 | 9.505 | 0.62 | | main-edit-into-1000-copies | 153.086 | 96.857 | 0.63 | | variant-switch-into-copies | 32.052 | 19.846 | 0.62 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
b5804addae
commit
1b2c74da68
@ -555,7 +555,7 @@
|
||||
[(:shape-ref shape) (d/without-nils (select-keys shape [:constraints-h :constraints-v]))]))))
|
||||
ids))
|
||||
|
||||
(defn- placed-like
|
||||
(defn placed-like
|
||||
"The main `objects` with the subtree of `shape-main` placed like `placed`,
|
||||
a copy shape expressed in the main's frame: resized to its size, its
|
||||
children following through their constraints and layouts, then turned
|
||||
|
||||
@ -581,6 +581,28 @@
|
||||
changes))
|
||||
changes)))
|
||||
|
||||
(defn- keep-moved-placement
|
||||
"A switch keeps the place of the copy shape `original-shape` it replaces.
|
||||
Inside a copy, a first corner that the position of `new-shape` would not
|
||||
give it needs a geometry override to survive later sync."
|
||||
[changes original-shape new-shape page libraries]
|
||||
(let [objects (pcb/get-objects changes)
|
||||
shape (get objects (:id new-shape))
|
||||
parent (get objects (:parent-id shape))
|
||||
position (when (and (:shape-ref parent)
|
||||
(ctk/touched-group? original-shape :geometry-group)
|
||||
(not (ctk/touched-group? shape :geometry-group)))
|
||||
(ctf/find-ref-shape nil (assoc page :objects objects) libraries shape
|
||||
:include-deleted? true :with-context? true))
|
||||
position-objects (:objects (:container (meta position)))
|
||||
position-parent (get position-objects (:parent-id position))
|
||||
placed (when position-parent
|
||||
(get (cll/placed-like position-objects position-parent parent {}) (:id position)))]
|
||||
(cond-> changes
|
||||
(and placed (not (gpt/close? (first (:points shape)) (first (:points placed)))))
|
||||
(pcb/update-shapes [(:id shape)] #(update % :touched ctk/set-touched-group :geometry-group)
|
||||
{: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
|
||||
@ -612,6 +634,10 @@
|
||||
|
||||
changes (sync-restored-position changes page libraries (:id new-shape))
|
||||
|
||||
changes (cond-> changes
|
||||
keep-touched?
|
||||
(keep-moved-placement shape new-shape page libraries))
|
||||
|
||||
;; Replacement keeps the head id and its cell. Cleanup during the
|
||||
;; temporary deletion must not change the parent's placement data.
|
||||
changes (cond-> changes
|
||||
|
||||
@ -1063,3 +1063,10 @@
|
||||
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :variant-diff false :rich-variants true
|
||||
:layout-copies true :text true}]
|
||||
:ops [[:delete 5 0 0 0] [:switch 3 0 0 0] [:transform 0 0 0 3] [:update-main 0 0 0 0]]}))))
|
||||
|
||||
(t/deftest generated-switch-keeps-a-moved-copy-child-in-place-as-its-own
|
||||
;; a copy child of a copy moved and switched to another variant keeps the
|
||||
;; moved place as its own geometry
|
||||
(t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :library true :rich-variants true
|
||||
:layout-copies true :text true}]
|
||||
:ops [[:nest 4 0 0 0] [:transform 1 0 0 3] [:switch 3 0 0 0]]}))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user