mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Check a switched head's kept place through its own constraints
A nested copy head in a copy that is resized apart from its main keeps its place as authored geometry when its constraint changes. Switching it keeps that place and, keeping the touched groups, its constraints, but the switch compared the place with its position placed through the main's own constraints. Where the two matched it dropped the geometry override, and the next sync of its parent moved the head through the constraints it carries. When a switch keeps the touched groups and the head authored its constraints, the kept place is compared with its position placed through those constraints, as sync places it. The harness model does the same. Test: switching-a-copy-head-keeps-the-place-its-own-constraint-kept. Focused switch, swap and composable tests pass (288 tests). Benchmark (alone): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+---------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 23.06 | 29.353 | 0.65 | | edit-through-a-chain-of-dependents | 68.931 | 46.664 | 61.416 | 0.68 | | library-update-into-copies | 83.083 | 49.118 | 51.106 | 0.59 | | main-edit-among-many-shapes | 4.837 | 2.744 | 3.366 | 0.57 | | main-edit-into-10-copies | 1.79 | 1.306 | 2.48 | 0.73 | | main-edit-into-100-copies | 15.415 | 11.34 | 12.203 | 0.74 | | main-edit-into-1000-copies | 153.086 | 130.776 | 191.745 | 0.85 | | variant-switch-into-copies | 32.052 | 22.084 | 26.522 | 0.69 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
dc485e2e08
commit
0009acf42d
@ -681,8 +681,10 @@
|
||||
(defn- keep-moved-placement
|
||||
"A swap 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]
|
||||
give it needs a geometry override to survive later sync. With
|
||||
`keep-touched?`, the constraints `original-shape` authors carry, and
|
||||
later sync places the new head through them."
|
||||
[changes original-shape new-shape page libraries keep-touched?]
|
||||
(let [objects (pcb/get-objects changes)
|
||||
shape (get objects (:id new-shape))
|
||||
parent (get objects (:parent-id shape))
|
||||
@ -693,8 +695,11 @@
|
||||
:include-deleted? true :with-context? true))
|
||||
position-objects (:objects (:container (meta position)))
|
||||
position-parent (get position-objects (:parent-id position))
|
||||
;; the constraints the new head carries as its own, by its position
|
||||
authored (when (and keep-touched? (ctk/touched-group? original-shape :constraints-group))
|
||||
{(:id position) (d/without-nils (select-keys shape [:constraints-h :constraints-v]))})
|
||||
placed (when position-parent
|
||||
(get (cll/placed-like position-objects position-parent parent {}) (:id position)))]
|
||||
(get (cll/placed-like position-objects position-parent parent authored) (: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)
|
||||
@ -786,7 +791,7 @@
|
||||
|
||||
changes (sync-restored-position changes page libraries (:id new-shape))
|
||||
|
||||
changes (cond-> (keep-moved-placement changes shape new-shape page libraries)
|
||||
changes (cond-> (keep-moved-placement changes shape new-shape page libraries keep-touched?)
|
||||
keep-touched?
|
||||
(keep-placement-overrides shape new-shape))
|
||||
|
||||
|
||||
@ -930,6 +930,11 @@
|
||||
(not= (boolean (:flip-y old-root)) (flip :flip-y)))
|
||||
;; a swap keeps the old head's layout item values, and their overrides
|
||||
layout-items (into {} (filter #(.startsWith (name (key %)) "layout-item-")) (get model root-id))
|
||||
;; the position as the head's constraints place it, when the head
|
||||
;; carries its own
|
||||
placing (cond-> after
|
||||
(and position (contains? (get result root-id) :constraints-group))
|
||||
(update (:id position) merge (select-keys root [:constraints-h :constraints-v])))
|
||||
;; a swap in a copy keeps an authored place its position does not give,
|
||||
;; unless a layout places the head
|
||||
kept-place? (and (:shape-ref parent) position
|
||||
@ -938,7 +943,7 @@
|
||||
(contains? (get model root-id) :geometry-group)
|
||||
(not (gpt/close? (first (:points root))
|
||||
(first (:points (geom/child-placement position (get after (:parent-id position))
|
||||
parent after))))))]
|
||||
parent placing))))))]
|
||||
(cond-> result
|
||||
retained-orientation?
|
||||
(assoc-in [root-id :geometry-group]
|
||||
|
||||
@ -2443,6 +2443,13 @@
|
||||
:grid-empty false :layout-copies false :text false}]
|
||||
:ops [[:transform 0 2 0 7] [:delete] [:switch] [:transform 1 1]]}))))
|
||||
|
||||
(t/deftest switching-a-copy-head-keeps-the-place-its-own-constraint-kept
|
||||
(t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout nil :variant-diff false
|
||||
:layout-item-margins false :grid-square false :rich-variants true
|
||||
:layout-children false :grid-empty false :layout-copies false :text true}]
|
||||
:ops [[:add-variant] [:variant-property 0 9 25] [:make-variant 11] [:resize 19]
|
||||
[:add-child] [:style 19 9 1] [:switch 9]]}))))
|
||||
|
||||
(t/deftest settling-a-bool-in-a-grid-copy-twice-keeps-its-shapes-in-place
|
||||
(t/is (map? (cg/run {:world [3 0 {:variants true :rich-variants true :text true :layout :grid
|
||||
:layout-copies true :layout-children true}]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user