From 6a5aa99f7909d16a79cc2b9e9fd6e9293499a27f Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 12 Nov 2026 23:07:27 +0100 Subject: [PATCH] :bug: Keep the geometry a shape in a copy group authors through sync When a shape in a group of a copy authors a move or a resize, the untouched group's bounds follow it. Sync moved or resized the group back to its main's bounds and carried its whole subtree with it, so the shape lost the geometry it authored. A group or bool takes its bounds from its children, which sync places one by one: a move or resize of its bounds now carries nothing, and the group fits its children again. A turn or flip still carries the subtree. Tests: syncing-a-copy-group-keeps-the-place-its-shape-authors, syncing-a-copy-group-keeps-the-size-its-shape-authors, undoing-a-turn-of-a-copy-group-gives-the-groups-of-its-copies-their-bounds-back. The full common suite passes. The benchmark of the previous commit covers this one. AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 16 +++++++++++++++- .../common_tests/logic/composable_gen_test.cljc | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 3816496173..87f6720669 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -673,7 +673,19 @@ (not= (boolean (:flip-x before)) (boolean (:flip-x after))) (not= (boolean (:flip-y before)) (boolean (:flip-y after))))) ids (when changed? (cfh/get-children-ids (:objects container) (:id before)))] - (if (seq ids) + (cond + ;; a group or bool takes its bounds from its children, which sync places + ;; one by one: a move or resize of its bounds carries nothing, and it + ;; fits them again + (and (seq ids) (or moved? resized?) + (mth/close? (or (:rotation before) 0) (or (:rotation after) 0) 1e-10) + (= (boolean (:flip-x before)) (boolean (:flip-x after))) + (= (boolean (:flip-y before)) (boolean (:flip-y after))) + (#{:group :bool} (:type before))) + (let [refit {:type :reg-objects :shapes [(:id before)]}] + (pcb/add-changes changes container [refit] [refit])) + + (seq ids) (let [orientation (fn [shape] (let [matrix (axes-matrix shape)] (assoc shape :transform matrix :transform-inverse (gmt/inverse matrix)))) @@ -704,6 +716,8 @@ (update :touched ctk/set-touched-group :geometry-group)) #(cond-> % (some? turn) turn :always (gsh/move delta))) {:ignore-touched true})) + + :else changes))) (defn- constraint-sized-main diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 8c4022dd28..dc362184b2 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2477,6 +2477,21 @@ :layout-copies false :layout-children true}] :ops [[:add-child 5] [:structure 12] [:transform 12 10 0 12]]})))) +(t/deftest syncing-a-copy-group-keeps-the-place-its-shape-authors + (t/is (map? (cg/run {:world [1 0 {:variants true :rich-variants false :text false :layout :grid + :layout-copies false :layout-children false}] + :ops [[:add-child 1] [:structure 2] [:transform 2 0 0 2]]})))) + +(t/deftest syncing-a-copy-group-keeps-the-size-its-shape-authors + (t/is (map? (cg/run {:world [1 0 {:variants true :rich-variants false :text false :layout :grid + :layout-copies false :layout-children false}] + :ops [[:add-child 1] [:structure 2] [:transform 2 2 0 2]]})))) + +(t/deftest undoing-a-turn-of-a-copy-group-gives-the-groups-of-its-copies-their-bounds-back + (t/is (map? (cg/run {:world [2 2 {:variants true :rich-variants true :text true :layout nil + :layout-copies false :layout-children false}] + :ops [[:add-child 7] [:add-child 7] [:structure 13] [:transform 10 15 0 12]]})))) + (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}]