mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Keep a detached nested copy child where it is
Detaching a copy links each nested copy to the next main up. A nested copy that keeps a size of its own then places its children against the new main's size, so a child with its own center constraint stayed in place at the detach but moved at the next sync of that component, with no change to the main. Detach now marks the geometry of each shape it links to a new main as the copy's own when its next sync would place it elsewhere, so it stays where it is. Swapped heads still take their new place. The model predicts the same override. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 20.643 | 0.59 | | edit-through-a-chain-of-dependents | 68.931 | 40.331 | 0.59 | | library-update-into-copies | 83.083 | 46.648 | 0.56 | | main-edit-among-many-shapes | 4.837 | 2.336 | 0.48 | | main-edit-into-10-copies | 1.79 | 0.995 | 0.56 | | main-edit-into-100-copies | 15.415 | 9.07 | 0.59 | | main-edit-into-1000-copies | 153.086 | 91.388 | 0.60 | | variant-switch-into-copies | 32.052 | 21.317 | 0.67 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
c73b30cb56
commit
7fd46d516b
@ -126,12 +126,14 @@
|
||||
objects (pcb/get-objects changes)
|
||||
advanced (into []
|
||||
(filter (fn [id]
|
||||
(let [before (get-in container [:objects id])
|
||||
after (get objects id)]
|
||||
(and (ctk/swapped? after)
|
||||
(not= (:shape-ref before) (:shape-ref after))))))
|
||||
(cfh/get-children-ids (:objects container) shape-id))]
|
||||
(cll/generate-sync-advanced-placement changes container libraries advanced))))
|
||||
(not= (get-in container [:objects id :shape-ref])
|
||||
(get-in objects [id :shape-ref]))))
|
||||
(cfh/get-children-ids (:objects container) shape-id))
|
||||
swapped? #(ctk/swapped? (get objects %))]
|
||||
(-> changes
|
||||
(cll/generate-sync-advanced-placement container libraries (filterv swapped? advanced))
|
||||
;; a nested copy keeps where it is when its new main would place it elsewhere
|
||||
(cll/generate-keep-advanced-placement container libraries (remove swapped? advanced))))))
|
||||
|
||||
(defn- generate-detach-recursive
|
||||
[changes container libraries shape-id first component-root?]
|
||||
|
||||
@ -1750,6 +1750,32 @@
|
||||
changes)))
|
||||
changes ids))
|
||||
|
||||
(defn generate-keep-advanced-placement
|
||||
"Make authored the geometry of the copy shapes `ids`, whose references
|
||||
advanced, when their next sync would place them elsewhere: their copy
|
||||
parent keeps overrides that the new main lacks. Parents come before
|
||||
their children, so each child is checked in its parent's settled frame."
|
||||
[changes container libraries ids]
|
||||
(reduce
|
||||
(fn [changes id]
|
||||
(let [objects (pcb/get-objects changes)
|
||||
container (assoc container :objects objects)
|
||||
shape (get objects id)
|
||||
parent (get objects (:parent-id shape))
|
||||
main (ctf/find-ref-shape nil container libraries shape
|
||||
:include-deleted? true :with-context? true)
|
||||
main-objects (:objects (:container (meta main)))
|
||||
main-parent (get main-objects (:parent-id main))]
|
||||
(if (and (some? (:shape-ref parent)) (some? main-parent)
|
||||
(not (ctk/touched-group? shape :geometry-group))
|
||||
(not (close-geometry? shape (get (placed-like main-objects main-parent parent
|
||||
(authored-constraints objects [id]))
|
||||
(:id main)))))
|
||||
(pcb/update-shapes changes [id] #(update % :touched ctk/set-touched-group :geometry-group)
|
||||
{:ignore-touched true})
|
||||
changes)))
|
||||
changes ids))
|
||||
|
||||
(defn- update-swapped-placement
|
||||
"Synchronizes a swapped copy head with the main shape it replaces, in the
|
||||
attributes that place it in its parent."
|
||||
|
||||
@ -1026,3 +1026,10 @@
|
||||
(t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :layout :flex :library true
|
||||
:rich-variants true :layout-copies true :text true}]
|
||||
:ops [[:style 0 23 18 0]]}))))
|
||||
|
||||
(t/deftest generated-detached-copy-child-with-its-own-constraint-stays-in-place
|
||||
;; a nested copy child with its own center constraint keeps its place when
|
||||
;; the copy around it is detached, as an override of its new main, and a
|
||||
;; later sync leaves it there
|
||||
(t/is (map? (cg/run {:world [2 2 {:text true :text-styles true}]
|
||||
:ops [[:style 8 9 3 1] [:resize 2 0 0 0] [:detach 3 0 0 0]]}))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user