diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index ab89c011c3..afe5a437be 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -375,7 +375,7 @@ (reduce #(update %1 %2 turn) objects (cfh/get-children-ids-with-self objects (:id shape-main))))))))) -(defn- reassign-parent-grid-cells +(defn reassign-parent-grid-cells "`changes` with the cells of the grid that holds the copy head `id` assigned again when they take the head in or out of the grid's flow, as showing or hiding a child does." diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 715d48dd32..44a7d9e0e7 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -793,9 +793,11 @@ ;; temporary deletion must not change the parent's placement data. changes (cond-> changes (ctsl/grid-layout? parent) - (pcb/update-shapes [(:id parent)] - #(assoc % :layout-grid-cells (:layout-grid-cells parent)) - {:ignore-touched true}))] + (-> (pcb/update-shapes [(:id parent)] + #(assoc % :layout-grid-cells (:layout-grid-cells parent)) + {:ignore-touched true}) + ;; a head that enters or leaves the flow takes or frees a cell + (cll/reassign-parent-grid-cells page (:id shape))))] [new-shape changes (concat all-parents parents-of-swapped)])) (defn find-switch-target diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 2b4fdd14bb..5684fbcf48 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2005,6 +2005,21 @@ :ops [[:duplicate 0 0 0 0] [:duplicate 0 0 0 0] [:variant-property 0 0 0 0] [:switch 12] [:duplicate 16 0 0 0] [:make-variant 0] [:switch 12] [:update-main 0 0 0 0]]})))) +(t/deftest switching-a-hidden-grid-child-to-a-shown-variant-gives-it-a-cell + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout :grid :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children false :grid-empty false :layout-copies true :text true}] + :ops [[:add-variant 0 0 0 0] [:add-variant 2] [:switch 5] [:nest 8 0 0 0] [:delete 0] + [:restore 0] [:style 6 1 1] [:variant-property 0 0 0 0] [:switch 0]]})))) + +(t/deftest switching-a-hidden-grid-child-of-a-library-variant-gives-it-a-cell + (t/is (map? (cg/run {:world [2 1 {:variants true :text-styles true :library-variants true :stale-libraries true + :layout :grid :layout-item-margins false :grid-square false :library-depth 1 + :library true :rich-variants true :layout-children false :library-text true + :grid-empty false :layout-copies true :text true}] + :ops [[:nest 6 0 0 0] [:style 3 1 1] [:library-variant-property 0 0 0 0] [:library-sync] + [:switch 6]]})))) + (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 diff --git a/common/test/common_tests/logic/variants_switch_target_test.cljc b/common/test/common_tests/logic/variants_switch_target_test.cljc index b82013cd6c..69039504eb 100644 --- a/common/test/common_tests/logic/variants_switch_target_test.cljc +++ b/common/test/common_tests/logic/variants_switch_target_test.cljc @@ -198,3 +198,32 @@ (t/is (= 3 (:column cell))) (t/is (= (:id cell) (:id cell'))) (t/is (= [(:id new-shape)] (:shapes cell'))))) + +(t/deftest switching-a-hidden-grid-child-to-a-shown-variant-gives-it-a-cell + (let [;; ==== Setup: :m01 is hidden, so its copy in the grid board holds no cell + file (-> (thf/sample-file :file1) + (thv/add-variant :v01 :c01 :m01 :c02 :m02 :variant1-params {:hidden true}) + (tho/add-grid-frame :board) + (ths/add-sample-shape :first :parent-label :board) + (thc/instantiate-component :c01 :copy01 :parent-label :board) + (tho/place-in-grid-columns :board 2 {1 :first})) + page (thf/current-page file) + + ;; ==== Action + [new-shape changes _] + (clv/generate-component-swap-in-place (pcb/empty-changes nil (:id page)) + page + (libraries file) + (:data file) + (ths/get-shape file :copy01) + (thi/id :c02) + true) + file' (thf/apply-changes file changes) + new-shape (ths/get-shape-by-id file' (:id new-shape)) + cell' (ctl/get-cell-by-shape-id (ths/get-shape file' :board) (:id new-shape))] + + ;; ==== Check: the shown head takes the free cell + (t/is (:hidden (ths/get-shape file :copy01))) + (t/is (nil? (ctl/get-cell-by-shape-id (ths/get-shape file :board) (thi/id :copy01)))) + (t/is (not (:hidden new-shape))) + (t/is (= 2 (:column cell')))))