mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Place copy children through the constraints they author
Resizing a copy placed its children through their own constraints, but sync then placed them again through the constraints of the main children they pair with. A child that authored a scale, right or left-right constraint went back to the main's left placement on the next sync, while partial sync kept the resized result. When sync places the main subtree like a resized copy, resize the main children with the constraints their copy children author. The swapped head placement step takes the head's authored constraints the same way. The generated oracle predicts copy child geometry with the same rule. A random common JavaScript structure run found this. Its shrunk program fails I4 against the old oracle and I6 against the old sync. The direct regression fails three of 15 assertions before the fix: each authored constraint places the child on resize, and sync moves it back. Both pass unchanged after the fix. Goldens are unchanged. Full common passes lint, JVM, JavaScript and formatting: JVM 2054 tests / 33757 assertions; JavaScript 1990 / 32348. All six component properties pass 40 programs each at seed 712 in both runtimes. Full rebuilt frontend passes 1798 / 15737. Backend passes 1838 / 9293 (a pool-statistics race failed once and passed on rerun); exporter passes 16 / 40. Consumer lint and formatting pass. The final nil filter on authored constraints ran in the focused sync, geometry and golden suites after the full runs. 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.885 0.49 Main into 100 copies 15.415 8.615 0.56 Main into 1000 copies 153.086 87.402 0.57 Three nesting levels 35.215 18.043 0.51 Dependency chain 68.931 35.277 0.51 Library update 83.083 43.810 0.53 Many plain shapes 4.837 2.070 0.43 Variant switch 32.052 19.557 0.61 AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
05c08b9e9a
commit
9eda12b819
@ -503,12 +503,24 @@
|
||||
(gsh/close-attrs? :points (:points shape) (:points other))
|
||||
(mth/close? (:content-scale shape 1) (:content-scale other 1))))
|
||||
|
||||
(defn- authored-constraints
|
||||
"The constraints that the copy shapes `ids` author, by the id of the main
|
||||
shape each one pairs with."
|
||||
[objects ids]
|
||||
(into {}
|
||||
(keep (fn [id]
|
||||
(let [shape (get objects id)]
|
||||
(when (ctk/touched-group? shape :constraints-group)
|
||||
[(:shape-ref shape) (d/without-nils (select-keys shape [:constraints-h :constraints-v]))]))))
|
||||
ids))
|
||||
|
||||
(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
|
||||
and moved with it as one piece."
|
||||
[objects shape-main placed]
|
||||
and moved with it as one piece. A child resizes through the constraints
|
||||
its copy authors (`authored`, by main shape id) instead of the main's."
|
||||
[objects shape-main placed authored]
|
||||
(let [scale (/ (:content-scale placed 1) (:content-scale shape-main 1))
|
||||
width (-> placed :selrect :width)
|
||||
height (-> placed :selrect :height)
|
||||
@ -517,7 +529,7 @@
|
||||
objects
|
||||
(let [modif-tree (gm/set-objects-modifiers
|
||||
{(:id shape-main) {:modifiers (ctm/change-size shape-main width height)}}
|
||||
objects)]
|
||||
(reduce-kv #(d/update-when %1 %2 merge %3) objects authored))]
|
||||
(reduce-kv (fn [objects id {:keys [modifiers]}]
|
||||
(d/update-when objects id gsh/transform-shape modifiers))
|
||||
objects
|
||||
@ -586,7 +598,9 @@
|
||||
(in-main-frame shape-inst (:root-inst ctx) (:root-main ctx)))
|
||||
main-container (cond-> main-container
|
||||
(and (some? placed) (not (close-geometry? placed shape-main)))
|
||||
(update :objects placed-like shape-main placed))
|
||||
(update :objects placed-like shape-main placed
|
||||
(authored-constraints (:objects container)
|
||||
(cfh/get-children-ids (:objects container) (:id shape-inst)))))
|
||||
ctx (assoc ctx :main-container main-container)
|
||||
shape-main (get-in main-container [:objects (:id shape-main)])
|
||||
changes (-> changes
|
||||
@ -1575,7 +1589,7 @@
|
||||
main-objects (:objects (:container (meta main)))
|
||||
main-parent (get main-objects (:parent-id main))]
|
||||
(if (and parent main-parent)
|
||||
(let [placed (get (placed-like main-objects main-parent parent) (:id main))]
|
||||
(let [placed (get (placed-like main-objects main-parent parent (authored-constraints objects [id])) (:id main))]
|
||||
(generate-take-placement changes shape placed objects
|
||||
(and (ctsl/any-layout-immediate-child? objects shape)
|
||||
(not (ctsl/position-absolute? shape)))))
|
||||
|
||||
@ -288,6 +288,27 @@
|
||||
(t/is (= box (child-box synced)) "the sync keeps it there")
|
||||
(t/is (= "#ff0000" (-> (ths/get-shape synced :copy-child) :fills first :fill-color)))))))
|
||||
|
||||
(t/deftest a-resized-copy-root-places-children-through-their-authored-constraints
|
||||
(doseq [[constraints-h box] [[:right [170 10 20 20]]
|
||||
[:scale [140 10 40 20]]
|
||||
[:leftright [70 10 120 20]]]]
|
||||
(t/testing (name constraints-h)
|
||||
(let [file (component-with-child :left)
|
||||
page (thf/current-page file)
|
||||
authored (thf/apply-changes file
|
||||
(cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
#{(thi/id :copy-child)}
|
||||
#(assoc % :constraints-h constraints-h)
|
||||
(:objects page)
|
||||
{}))
|
||||
resized (resize authored :copy-root 200 100)
|
||||
synced (edit-and-sync resized)]
|
||||
(t/is (= #{:constraints-group} (:touched (ths/get-shape resized :copy-child))))
|
||||
(t/is (= box (child-box resized)) "the resize places the child")
|
||||
(t/is (= box (child-box synced)) "the sync keeps it there")
|
||||
(t/is (= constraints-h (:constraints-h (ths/get-shape synced :copy-child))))
|
||||
(t/is (= "#ff0000" (-> (ths/get-shape synced :copy-child) :fills first :fill-color)))))))
|
||||
|
||||
(t/deftest a-copy-root-resized-with-its-content-touches-only-the-root
|
||||
(let [file (-> (component-with-child :scale)
|
||||
(ths/update-shape :main-child :strokes [{:stroke-color "#000000" :stroke-opacity 1
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
[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.composable.grid :as grid]
|
||||
[app.common.test-helpers.composable.oracle :as oracle]
|
||||
[app.common.test-helpers.composable.shadow :as shadow]
|
||||
[app.common.test-helpers.composable.variants :as variants]
|
||||
@ -19,7 +20,9 @@
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
[app.common.test-helpers.texts :as thtx]
|
||||
[clojure.test :as t]))
|
||||
[app.common.uuid :as uuid]
|
||||
[clojure.test :as t]
|
||||
[clojure.walk :as walk]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
@ -645,6 +648,20 @@
|
||||
[:undo] [:redo] [:reset 0] [:sync 1]
|
||||
[:switch 1 0 0 0] [:detach 0 0 0 0] [:delete 0 0 0 0]]}))))
|
||||
|
||||
(t/deftest resizing-a-copy-scales-a-child-through-its-authored-constraint
|
||||
(let [program {:world [2 1 {:text true :text-styles true :layout nil}]
|
||||
:ops [[:delete 0 0 0 0] [:style 5 9 1] [:resize 1 0 0 0]]}
|
||||
situation (:situation (cg/run program))
|
||||
file (tm/file situation)
|
||||
page (thf/current-page file)
|
||||
child (:shape (first (filter #(= [2 0 0] (:path %)) (cg/tree situation))))
|
||||
expected (oracle/expected-geometry file page (cf/libraries situation) child)]
|
||||
(t/is (= :scale (:constraints-v child)))
|
||||
(t/is (= #{:constraints-group} (:touched child)))
|
||||
;; The parent shrinks from 100 to 80, so a scaled 50 child becomes 40.
|
||||
(t/is (gsh/close-attrs? :height 40 (:height expected) 0.01))
|
||||
(t/is (gsh/close-attrs? :height 40 (:height child) 0.01))))
|
||||
|
||||
(t/deftest detached-swapped-head-follows-its-own-component-without-position-overrides
|
||||
(t/is (map? (cg/run {:world [2 1 {:library true :variants true}]
|
||||
:ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user