diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index afe5a437be..6068ddb0db 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -660,9 +660,11 @@ (assoc shape :transform matrix :transform-inverse (gmt/inverse matrix)))) turn (orient-like (orientation before) (orientation after) (gsh/shape->center before)) delta (gpt/subtract (gsh/shape->center after) (gsh/shape->center before)) - ;; the subtree as the sync left it, under the parent before the sync + ;; the subtree as the sync left it, under the parent placed as before the sync placed (when resized? - (placed-like (assoc (pcb/get-objects changes) (:id before) before) before after {}))] + (placed-like (assoc (pcb/get-objects changes) (:id before) + (merge after (select-keys before placement-geometry-attrs))) + before after {}))] (pcb/update-shapes changes ids (if resized? #(get placed (:id %) %) @@ -1980,29 +1982,41 @@ fixes it, and the layout child attributes of each of its children, from the child of `src` it pairs with (`src-child`); a child with none is left as it is. With `omit-touched?`, an attribute whose group is touched is - left as it is." + left as it is. A grid `dest` assigns its cells again when that takes a + child in or out of its flow." [changes container dest src src-child omit-touched?] - (pcb/concat-changes - changes - (-> (pcb/empty-changes) - (pcb/with-container container) - (pcb/with-objects (:objects container)) - (pcb/update-shapes - [(:id dest)] - (fn [dest] - (cond-> dest - (contains? #{:auto :fix} (:layout-item-h-sizing src)) - (propagate-attrs src #{:layout-item-h-sizing} omit-touched?) + (let [objects (:objects container) + propagated #(if-let [src-child (src-child %)] + (propagate-attrs % src-child layout-child-attrs omit-touched?) + %) + ;; whether a child enters or leaves the flow of a grid + reflow? (and (ctsl/grid-layout? dest) + (some #(let [child (get objects %)] + (and child + (not= (ctsl/position-absolute? child) + (ctsl/position-absolute? (propagated child))))) + (:shapes dest)))] + (pcb/concat-changes + changes + (cond-> (-> (pcb/empty-changes) + (pcb/with-container container) + (pcb/with-objects objects) + (pcb/update-shapes + [(:id dest)] + (fn [dest] + (cond-> dest + (contains? #{:auto :fix} (:layout-item-h-sizing src)) + (propagate-attrs src #{:layout-item-h-sizing} omit-touched?) - (contains? #{:auto :fix} (:layout-item-v-sizing src)) - (propagate-attrs src #{:layout-item-v-sizing} omit-touched?))) - {:ignore-touched true}) - (pcb/update-shapes - (:shapes dest) - #(if-let [src-child (src-child %)] - (propagate-attrs % src-child layout-child-attrs omit-touched?) - %) - {:ignore-touched true})))) + (contains? #{:auto :fix} (:layout-item-v-sizing src)) + (propagate-attrs src #{:layout-item-v-sizing} omit-touched?))) + {:ignore-touched true}) + (pcb/update-shapes (:shapes dest) propagated {:ignore-touched true})) + reflow? + (pcb/update-shapes [(:id dest)] ctsl/assign-cells {:with-objects? true :ignore-touched true}) + + (and reflow? (= :page (:type container))) + (pcb/reorder-grid-children [(:id dest)]))))) (defn- add-inherited-grid-cells "Add default cells in newly inherited tracks without replacing authored cells." diff --git a/common/test/common_tests/logic/comp_reset_test.cljc b/common/test/common_tests/logic/comp_reset_test.cljc index 6975606485..27cb707288 100644 --- a/common/test/common_tests/logic/comp_reset_test.cljc +++ b/common/test/common_tests/logic/comp_reset_test.cljc @@ -50,6 +50,31 @@ (t/is (= 2 (column reset))) (t/is (nil? (:touched (tm/resolve-shape reset :copy-nested)))))) +(t/deftest reset-a-resized-grid-copy-gives-a-cell-to-the-child-it-brings-back-into-the-flow + (let [;; ==== Setup: the copy takes Item B out of the flow and narrows itself + file (-> (thf/sample-file :file1) + (tho/add-grid-frame :main-root) + (tho/add-rect :main-a :parent-label :main-root) + (tho/add-rect :main-b :parent-label :main-root) + (tho/place-in-grid-columns :main-root 2 {1 :main-a 2 :main-b}) + (thc/make-component :grid :main-root) + (thc/instantiate-component :grid :copy :children-labels [:copy-a :copy-b])) + initial (tm/make-situation file) + edited (-> initial + (r/step (n/change-property :copy-b :layout-item-absolute true)) r/settle + (r/step (n/transform-shape :copy :width 80)) r/settle) + + ;; ==== Action + reset (-> edited (r/step (n/reset :copy)) r/settle) + column (fn [s] + (:column (ctl/get-cell-by-shape-id (tm/resolve-shape s :copy) (thi/id :copy-b))))] + + ;; ==== Check: Item B is back in its main's cell + (t/is (nil? (column edited))) + (t/is (= 80.0 (:width (tm/resolve-shape edited :copy)))) + (t/is (= 2 (column reset))) + (t/is (nil? (:touched (tm/resolve-shape reset :copy-b)))))) + (t/deftest reset-a-nested-copy-through-a-deleted-outer-main (let [initial (setup/nested-component-with-copy) edited (-> initial diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 5684fbcf48..b87304f8ad 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2020,6 +2020,13 @@ :ops [[:nest 6 0 0 0] [:style 3 1 1] [:library-variant-property 0 0 0 0] [:library-sync] [:switch 6]]})))) +(t/deftest resetting-a-resized-grid-copy-gives-a-cell-to-the-child-back-in-its-flow + (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles true :layout :grid :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children true :grid-empty false :layout-copies true :text true}] + :ops [[:make-variant 4 0 0 0] [:combine 0 0 0 0] [:transform 6 7 0 0] [:nest 1 0 0 0] + [:combine 3] [:switch 6] [:style 16 35 1] [:edit 8 1 1 :copy-head] [:reset 8]]})))) + (t/deftest turning-a-flipped-copy-turns-a-child-stored-as-the-other-mirror-turn (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false :layout-item-margins false :grid-square false :rich-variants true