📎 Re-anchor an authored position when its shape's constraints change

A copy shape's authored geometry is checked where it sits in the parent
it was authored in, resized through its constraints as that parent
resizes. A constraint edit after a resize of that parent replayed the
resize through the new constraint, though the edit moves nothing and
applies only to later resizes. A constraint edit now anchors the
authored position where the shape sits.

Harness only; the benchmark is not run.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-09 10:09:16 +01:00
parent 53e1b7634f
commit ef028ce116
3 changed files with 23 additions and 1 deletions

View File

@ -913,7 +913,12 @@
;; layout gave it, which no parent placement authored
(and (= property :layout-item-absolute) (true? value)
(:shape-ref shape) (not (:layout-item-absolute shape)))
(assoc-in [id :geometry-group] (shadow/author-geometry (get (all-objects after) id shape) nil)))
(assoc-in [id :geometry-group] (shadow/author-geometry (get (all-objects after) id shape) nil))
;; a constraint resizes the shape only with its parent's later resizes
(and (#{:constraints-h :constraints-v} property) (get-in model [id :geometry-group]))
(update-in [id :geometry-group] shadow/anchor-position (get (all-objects after) id shape)
(get (all-objects after) (:parent-id shape))))
(:grid-cell :grid-direction) (grid/edit model shape (:action op) (:value op))
:reset (shadow/clear-subtree model objects id)
:update-main (shadow/update-main model objects (all-objects after) id)

View File

@ -124,6 +124,15 @@
(cond-> (values shape :geometry-group)
parent (with-meta {::position {:shape shape :parent parent :sized? sized?}}))))
(defn anchor-position
"The authored geometry `value` placed from where `shape` sits now in
`parent`: a constraint change moves nothing and applies only to the
resizes after it."
[value shape parent]
(cond-> value
(::position (meta value))
(vary-meta update ::position assoc :shape shape :parent parent)))
(defn- authored-placement
"Where the shape `expected` records it authored sits in `parent`, resized
through the constraints of `current` when given (they apply to the

View File

@ -1928,6 +1928,14 @@
[:reset 0 0 0 0] [:nest 14 0 0 0] [:switch 6 0 0 0] [:style 11 29 1]
[:reset 2]]}))))
(t/deftest constraining-a-shape-after-its-parent-resized-keeps-it-in-place
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false
:layout-item-margins false :grid-square false :rich-variants true
:layout-children false :grid-empty false :layout-copies true :text true}]
:ops [[:detach 7 0 0 0] [:combine 21 0 0 0] [:detach 9 0 0 0] [:add-variant 9 0 0 0]
[:transform 12 0 0 18] [:add-variant 8] [:switch 0] [:add-variant 11 0 0 0]
[:resize 25 0 0 0] [:style 22 9 1]]}))))
(t/deftest random-variant-compositions
(let [coverage (atom {})
failure (atom nil)]