diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 69ed1f659c..c8907394b5 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -567,6 +567,16 @@ [(:shape-ref shape) (d/without-nils (select-keys shape [:constraints-h :constraints-v]))])))) ids)) +(defn- sized-like + "`shape` resized to the size of `source` about its first corner." + [shape source] + (let [width (-> source :selrect :width) + height (-> source :selrect :height)] + (if (and (mth/close? width (-> shape :selrect :width)) + (mth/close? height (-> shape :selrect :height))) + shape + (gsh/transform-shape shape (ctm/change-size shape width height))))) + (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 @@ -1313,7 +1323,15 @@ position-objects (get-in (meta position) [:container :objects]) ;; the head takes the place the replaced child authored placement (set/intersection (set (:touched replaced)) placement-groups) - positioned (mapv take-position new-shapes) + ;; a plain copy of the position has its size, unless the replaced child authored its geometry + sized? (fn [shape] + (and (= (:id shape) (:id new-head)) position + (not (ctk/swapped? shape)) + (not (contains? placement :geometry-group)))) + positioned (mapv (fn [shape] + (let [shape (take-position shape)] + (cond-> shape (sized? shape) (sized-like position)))) + new-shapes) by-id (d/index-by :id positioned) head (get by-id (:id new-head)) ;; the position's subtree placed like a head that is a plain copy of it diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 1ba3e40a7d..28d12c3702 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2109,6 +2109,13 @@ [:add-variant] [:add-variant] [:add-variant] [:switch 4] [:transform 0 0 0 7] [:update-main 22]]})))) +(t/deftest updating-a-main-with-a-swap-to-its-position-component-gives-the-head-the-positions-size + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles false :layout :grid :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 [[:variant-property] [:switch 3] [:combine 11] [:combine 12] [:resize 10] + [:variant-property 8 9] [:add-variant] [:switch 2] [:update-main]]})))) + (t/deftest moving-a-flex-copy-child-after-a-switch-resized-its-sibling-authors-no-geometry (t/is (map? (cg/run {:world [1 2 {:variants true :text-styles false :layout :flex :variant-diff false :layout-item-margins false :grid-square false :rich-variants true