diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 9f05d9221d..47690443de 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -1143,7 +1143,7 @@ :only-main (fn [changes child-main] (remove-shape changes child-main main-container)) :inverse? true}) - (reorder-main-children shape-main children-inst @added main-container)) + (reorder-main-children shape-main shape-inst children-inst @added main-container)) (ctsl/grid-layout? shape-main) (update-grid-main-attrs shape-main shape-inst children-inst @added main-container))))) @@ -1151,9 +1151,18 @@ (defn- reorder-main-children "Order the children of `shape-main` as the copy's `children-inst`, each by the main shape it pairs with or the one `added` for it, in one change that - its undo reverts." - [changes shape-main children-inst added main-container] - (let [order (into [] (keep #(get added (:id %) (:shape-ref %))) children-inst) + its undo reverts. A main that is a grid copy with its own cells, once it + takes the copy's, orders them as they flow in those cells, as sync orders + such a copy." + [changes shape-main shape-inst children-inst added main-container] + (let [own-flow? (and (:shape-ref shape-main) (ctsl/grid-layout? shape-main) (ctsl/grid-layout? shape-inst) + (or (ctk/touched-group? shape-main :layout-grid-cells) + (ctk/touched-group? shape-inst :layout-grid-cells))) + children-inst (if own-flow? + (let [by-id (d/index-by :id children-inst)] + (into [] (keep by-id) (:shapes (ctsl/reorder-grid-children shape-inst)))) + children-inst) + order (into [] (keep #(get added (:id %) (:shape-ref %))) children-inst) reorder (fn [shapes] {:type :reorder-children :parent-id (:id shape-main) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index c5379ae727..edc37eae3d 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -4209,3 +4209,11 @@ (t/is (map? (cg/run {:world [1 1 {:variants true :rich-variants true :text false :layout :flex :layout-copies false :layout-children true}] :ops [[:add-child] [:add-child] [:structure 7 8] [:transform 10 20 0 17]]})))) + +(t/deftest generated-updating-a-main-grid-copy-with-its-own-cells-orders-it-by-their-flow + ;; an update main that turns the direction of a nested grid copy with its + ;; own cells orders that copy's children as they flow in the new direction + (t/is (map? (cg/run {:world [3 2 {:variants false :layout :grid :layout-item-margins false :grid-square true + :rich-variants false :layout-children true :grid-empty false + :layout-copies false :text false}] + :ops [[:remove-child 7] [:grid-direction 13 0 7 1] [:grid-cell 0 0 0 1] [:update-main 17]]}))))