mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Place a reset nested copy where its main puts it
Reset syncs a copy head as the root of its own sync, and sync aligns the main with that root, so the root keeps its position. That is right for a top copy, whose position is its own. A nested head's placement inside its parent belongs to the parent's main: resetting a moved nested head cleared its geometry override and left it moved, untouched and different from its main. After the reset, place a nested head's subtree through a sync of the head that owns its ref, taking only placement attributes. That sync reads the loaded main, so it runs only when the reset clears a geometry override: a head whose geometry was not overridden already holds the placement it accepted, and placing it again gave a head whose only override was its opacity a pending, unaccepted 45-degree turn of its library main. Re-runs of the seed-20261101 library and library dependency properties found both cases. The regressions fail before the fix and pass after it: the head and its child return to their positions, undo restores the move, and the pending turn stays out. Compare lower-quantile milliseconds with the saved baseline; keep that baseline unchanged. The machine/JVM warning makes ratios rough. No world is flagged. World Baseline Now Ratio Main into 10 copies 1.790 0.996 0.56 Main into 100 copies 15.415 9.366 0.61 Main into 1000 copies 153.086 97.895 0.64 Three nesting levels 35.215 19.167 0.54 Dependency chain 68.931 38.467 0.56 Library update 83.083 46.702 0.56 Many plain shapes 4.837 3.332 0.69 Variant switch 32.052 22.433 0.70 AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
a44321fc4d
commit
2a71cf0292
@ -1960,11 +1960,50 @@
|
||||
data' file-id (changed-components data sync)
|
||||
libraries current-file-id 1)))
|
||||
|
||||
(defn- settle-reset-placement
|
||||
"Place a reset nested head whose geometry was overridden as an ordinary
|
||||
copy of its position: its subtree takes the placement a sync of the head
|
||||
that owns its ref gives. Other heads keep the placement they have."
|
||||
[changes file libraries container shape-id]
|
||||
(let [objects (pcb/get-objects changes)
|
||||
shape (get objects shape-id)
|
||||
parent (get objects (:parent-id shape))]
|
||||
(if (and (= :page (:type container))
|
||||
(:shape-ref parent)
|
||||
(not (ctk/swapped? shape))
|
||||
(ctk/touched-group? (ctn/get-shape container shape-id) :geometry-group))
|
||||
(let [container (ctn/make-container (assoc container :objects objects) :page)
|
||||
component (ctf/find-ref-component file container libraries shape :include-deleted? true)
|
||||
head (d/seek #(= (:id component) (:component-id %))
|
||||
(ctn/get-parent-copy-heads objects parent))]
|
||||
(if head
|
||||
(let [file (assoc-in file [:data :pages-index (:id container) :objects] objects)
|
||||
proposal (generate-sync-shape-direct (-> (pcb/empty-changes)
|
||||
(pcb/with-container container)
|
||||
(pcb/with-objects objects))
|
||||
file (assoc libraries (:id file) file)
|
||||
container (:id head) false)
|
||||
placed (pcb/get-objects proposal)]
|
||||
(pcb/update-shapes
|
||||
changes (cfh/get-children-ids-with-self objects shape-id)
|
||||
(fn [shape]
|
||||
(let [expected (get placed (:id shape))
|
||||
attrs (cond-> placement-geometry-attrs
|
||||
(= :path (:type shape)) (conj :content))]
|
||||
(if (= (:type shape) (:type expected))
|
||||
(merge shape (select-keys expected attrs))
|
||||
shape)))
|
||||
{:ignore-touched true}))
|
||||
changes))
|
||||
changes)))
|
||||
|
||||
(defn generate-reset-component
|
||||
"Reset the copy head to its near main. A swapped head turns back into the
|
||||
component of the main shape it refers to, keeping its id."
|
||||
component of the main shape it refers to, keeping its id. A nested head
|
||||
also takes its position's placement."
|
||||
[changes file-full libraries container id]
|
||||
(-> changes
|
||||
(pcb/with-container container)
|
||||
(pcb/with-objects (:objects container))
|
||||
(generate-sync-shape-direct file-full libraries container id true)))
|
||||
(generate-sync-shape-direct file-full libraries container id true)
|
||||
(settle-reset-placement file-full libraries container id)))
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
[app.common.test-helpers.composable.comp.runner :as r]
|
||||
[app.common.test-helpers.composable.comp.setups :as setup]
|
||||
[app.common.test-helpers.composable.core :as tm]
|
||||
[app.common.test-helpers.composable.gen :as cg]
|
||||
[app.common.test-helpers.compositions :as tho]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
@ -650,3 +651,25 @@
|
||||
(t/is (gsh/close-attrs? :points (:points child) (:points after) 0.001))
|
||||
(t/is (= (:rotation child) (:rotation after)))
|
||||
(t/is (nil? (:touched (tm/role-shape reset :copy-instance))))))
|
||||
|
||||
(t/deftest reset-a-moved-nested-copy-returns-it-to-its-position
|
||||
(let [initial (setup/nested-component-with-copy)
|
||||
head (tm/role-shape initial :copy-instance)
|
||||
child (tm/shape-by-id initial (first (:shapes head)))
|
||||
moved (-> initial (r/step (n/transform-shape :copy-instance :move [5 -3])) r/settle)
|
||||
reset (-> moved (r/step (n/reset :copy-instance)) r/settle)
|
||||
after (tm/role-shape reset :copy-instance)]
|
||||
(t/is (gsh/close-attrs? :points (:points head) (:points after) 0.001))
|
||||
(t/is (gsh/close-attrs? :points (:points child) (:points (tm/shape-by-id reset (:id child))) 0.001))
|
||||
(t/is (nil? (:touched after)))
|
||||
(t/is (= (thn/normalize-file (tm/file moved)) (thn/normalize-file (tm/file (r/step reset (n/undo))))))
|
||||
(t/is (map? (cg/run {:world [2 0 {:variants true :rich-variants true :text true :text-styles true
|
||||
:library true :layout-copies true}]
|
||||
:ops [[:delete 0 0 0 0] [:nest 4 0 0 0] [:transform 6 0 0 13]
|
||||
[:edit 4 1 1 :copy-head] [:reset 4]]})))))
|
||||
|
||||
(t/deftest reset-keeps-an-unmoved-nested-copy-in-its-accepted-placement
|
||||
;; The library turned the copy's main; the consumer has not accepted it.
|
||||
(t/is (map? (cg/run {:world [2 0 {:library true :stale-libraries true
|
||||
:library-dependency true :library-text true}]
|
||||
:ops [[:library-transform 14 3 0 0] [:edit 13 1 1 :copy-head] [:reset 13]]}))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user