diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 3c95ee194c..12ab7fb0b5 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -2152,11 +2152,19 @@ :include-deleted? true :with-context? true) main-objects (:objects (:container (meta main))) main-parent (get main-objects (:parent-id main)) + ;; a group or bool takes its bounds from its children, so they are + ;; placed in the board around it + board? (and (#{:group :bool} (:type parent)) (#{:group :bool} (:type main-parent)) + (not (ctsl/any-layout? (get objects (:frame-id shape))))) + parent (if board? (get objects (:frame-id shape)) parent) + main-parent (if board? (get main-objects (:frame-id main)) main-parent) ;; a layout places the shape, so only its size and orientation can be its own layout-placed? (and (ctsl/any-layout-immediate-child? objects shape) (not (ctsl/position-absolute? shape)))] (if (and (some? main) (not (ctk/touched-group? shape :geometry-group)) + ;; the bounds of a group or bool follow its children's places + (not (#{:group :bool} (:type shape))) (if (and (some? (:shape-ref parent)) (not layout-placed?)) (and (some? main-parent) (not (close-geometry? shape (get (placed-like main-objects main-parent parent diff --git a/common/src/app/common/test_helpers/composable/shadow.cljc b/common/src/app/common/test_helpers/composable/shadow.cljc index 77273fa7ae..945c2221ff 100644 --- a/common/src/app/common/test_helpers/composable/shadow.cljc +++ b/common/src/app/common/test_helpers/composable/shadow.cljc @@ -389,12 +389,20 @@ (let [parent (get after (:parent-id shape)) main (get after (:shape-ref shape)) main-parent (get after (:parent-id main)) + ;; a group or bool takes its bounds from its children, so they + ;; measure from the board around it + board? (and (#{:group :bool} (:type parent)) (#{:group :bool} (:type main-parent)) + (not (ctl/any-layout? (get after (:frame-id shape))))) + parent (if board? (get after (:frame-id shape)) parent) + main-parent (if board? (get after (:frame-id main)) main-parent) objects (cond-> after (and main (contains? groups :constraints-group)) (update (:id main) merge (into {} (filter val) (select-keys shape [:constraints-h :constraints-v]))))] (cond - (or (contains? groups :geometry-group) (contains? groups :swap-group) (nil? main)) + ;; the bounds of a group or bool follow its children's places + (or (contains? groups :geometry-group) (contains? groups :swap-group) (nil? main) + (#{:group :bool} (:type shape))) groups ;; a layout places the shape, so only its size and orientation can be its own diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index bdb521db18..f4aad0e201 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2508,6 +2508,12 @@ :layout-copies true :text false}] :ops [[:grid-track 3 5 0 2] [:grid-track 0 3] [:grid-cell 3 0 0 1]]})))) +(t/deftest detaching-keeps-a-shape-of-a-copy-bool-unauthored-where-its-main-places-it + (t/is (map? (cg/run {:world [2 2 {:variants true :rich-variants true :text true :layout :flex + :layout-copies false :layout-children false}] + :ops [[:delete 11] [:detach 5] [:swap 10] [:add-child] [:structure 0 6 3] [:nest 11] + [:transform 2 0 0 7] [:detach 13]]})))) + (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}]