diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 502c72c9c9..97fa704c0d 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -2242,6 +2242,10 @@ (:shapes shape-copy))] (-> shape-copy (assoc :layout-grid-cells (-> shape-main (ctsl/remap-grid-cells ids-map) :layout-grid-cells)) + ;; a copy with its own track lists keeps its main's cells within them + (cond-> (or (not= (count (:layout-grid-rows shape-copy)) (count (:layout-grid-rows shape-main))) + (not= (count (:layout-grid-columns shape-copy)) (count (:layout-grid-columns shape-main)))) + (ctsl/fit-cells-to-tracks)) (ctsl/assign-cells objects)))) (defn grid-direction-cells diff --git a/common/src/app/common/test_helpers/composable/grid.cljc b/common/src/app/common/test_helpers/composable/grid.cljc index daaebd2979..3e6abbfd5f 100644 --- a/common/src/app/common/test_helpers/composable/grid.cljc +++ b/common/src/app/common/test_helpers/composable/grid.cljc @@ -163,10 +163,10 @@ (def ^:private default-cell {:row-span 1 :column-span 1 :position :auto :align-self :auto :justify-self :auto :shapes []}) -(defn- fit-cells +(defn fit-cells "`cells` placed within a grid of `rows` by `columns` that flows in `direction`, as the contract keeps a copy's cells when its inherited - tracks shrink: cells with children first, then authored empty ones, then + tracks shrink, or the cells it takes from a main with other tracks: cells with children first, then authored empty ones, then default ones, each where it fits, else in the first free slot, else in one track; children left without a slot join the cell where theirs would start. Free slots take default cells." diff --git a/common/src/app/common/test_helpers/composable/oracle.cljc b/common/src/app/common/test_helpers/composable/oracle.cljc index 6477c41e58..1afb2da266 100644 --- a/common/src/app/common/test_helpers/composable/oracle.cljc +++ b/common/src/app/common/test_helpers/composable/oracle.cljc @@ -661,7 +661,14 @@ (and manual (= :auto (:position cell))) (assoc :position :manual)))])) [false []] cells))) - cells (->> (grid-cells main) + rows (count (:layout-grid-rows shape)) + columns (count (:layout-grid-columns shape)) + ;; a copy with its own track lists keeps its main's cells within them + fitted (if (and (= rows (count (:layout-grid-rows main))) + (= columns (count (:layout-grid-columns main)))) + (grid-cells main) + (grid/fit-cells (grid-cells main) rows columns (or (:layout-grid-dir shape) :row))) + cells (->> fitted (sort-by flow-order) (mapv #(update % :shapes (fn [ids] (filterv participating ids)))) end-auto-prefix) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index de3a91c5c9..164b92321f 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2381,6 +2381,12 @@ :layout-copies true :text true}] :ops [[:nest 6 0 0 0] [:nest 9 0 0 0] [:style 2 29 1] [:detach 5 0 0 0]]})))) +(t/deftest a-copy-with-its-own-columns-takes-its-main-cells-within-them + (t/is (map? (cg/run {:world [1 0 {:variants false :layout :grid :layout-item-margins false :grid-square false + :rich-variants false :layout-children false :grid-empty false + :layout-copies false :text false}] + :ops [[:grid-track 10 5 0 11] [:grid-track 0 1] [:grid-cell 0 0 0 1]]})))) + (t/deftest random-shape-structure-compositions (let [coverage (atom {}) failure (atom nil)]