diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index bee71b33a1..3c95ee194c 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -2292,6 +2292,26 @@ :layout-grid-columns (:layout-grid-columns target)) (ctsl/fit-cells-to-tracks))))) +(defn- keep-cell-ids + "`shape` with the cells its tracks add, those its main `shape-main` lacks, + under the ids of the cells of `shape-copy` in the same place, so each sync + gives them the same ids." + [shape shape-copy shape-main] + (let [place (juxt :row :column :row-span :column-span) + main-ids (set (keys (:layout-grid-cells shape-main))) + previous (into {} + (comp (map val) + (remove #(contains? main-ids (:id %))) + (map (juxt place :id))) + (:layout-grid-cells shape-copy))] + (update shape :layout-grid-cells + (fn [cells] + (into {} + (map (fn [[id cell]] + (let [id (if (contains? main-ids id) id (get previous (place cell) id))] + [id (assoc cell :id id)]))) + cells))))) + (defn copy-grid-cells "The grid copy `shape-copy` with the cells of its main `shape-main`, its own children in place of the main's, laid out in its own direction: the @@ -2313,7 +2333,8 @@ ;; 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/fit-cells-to-tracks) + (keep-cell-ids shape-copy shape-main))) (ctsl/assign-cells objects)))) (defn grid-direction-cells diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 3b7f7d9788..bdb521db18 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2502,6 +2502,12 @@ :layout-copies false :layout-children true}] :ops [[:rotate] [:add-child] [:structure 17] [:update-main]]})))) +(t/deftest syncing-a-copy-with-its-own-columns-keeps-the-ids-of-their-cells + (t/is (map? (cg/run {:world [1 2 {:variants false :layout :grid :layout-item-margins false :grid-square false + :rich-variants false :layout-children true :grid-empty true + :layout-copies true :text false}] + :ops [[:grid-track 3 5 0 2] [:grid-track 0 3] [:grid-cell 3 0 0 1]]})))) + (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}]