diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index e8e68f51da..1eaadca276 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -372,6 +372,24 @@ (reduce #(update %1 %2 turn) objects (cfh/get-children-ids-with-self objects (:id shape-main))))))))) +(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." + [changes container id] + (let [before (:objects container) + parent-id (:parent-id (get before id))] + (if (ctsl/grid-layout? before parent-id) + (let [changes (pcb/apply-changes-local changes) + after (pcb/get-objects changes)] + (if (and (contains? after id) + (not= (ctsl/position-absolute? before id) (ctsl/position-absolute? after id))) + (-> changes + (pcb/update-shapes [parent-id] ctsl/assign-cells {:with-objects? true :ignore-touched true}) + (pcb/reorder-grid-children [parent-id])) + changes)) + changes))) + (defn generate-sync-shape-direct "Generate changes to synchronize one shape that is the root of a component instance, and all its children, from the given component." @@ -397,17 +415,18 @@ library file libraries component) main-container (main-in-parent-orientation main-container shape-main container shape-inst reset?) shape-main (ctn/get-shape main-container (:id shape-main))] - (sync-copy-recursive changes - {:container container - :main-container main-container - :component component - :library library - ;; Reset also places new children in the main's frame. - :root-inst (cond-> shape-inst reset? (dissoc :touched)) - :root-main shape-main - :reset? reset?} - shape-inst - shape-main)) + (-> (sync-copy-recursive changes + {:container container + :main-container main-container + :component component + :library library + ;; Reset also places new children in the main's frame. + :root-inst (cond-> shape-inst reset? (dissoc :touched)) + :root-main shape-main + :reset? reset?} + shape-inst + shape-main) + (reassign-parent-grid-cells container shape-id))) ;; If the component is not found, because the master component has been ;; deleted or the library unlinked, do nothing. diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 76dcbf4219..a21cc754cb 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -860,3 +860,17 @@ child (some #(when (:layout-item-absolute %) %) (vals objects))] (t/is (:shape-ref child)) (t/is (contains? (:touched child) :geometry-group)))) + +(t/deftest generated-reset-shows-a-hidden-head-back-in-its-grid-cell + ;; a detached grid holds a nested head its copy hid; the reset shows it + ;; again, and the resize lays the grid out + (let [result (cg/run {:world [2 0 {:text true :text-styles true :layout :grid}] + :ops [[:nest 0 0 0 0] [:detach 1 0 0 0] [:style 1 1 1 1] + [:edit 1 1 1 :copy-head] [:reset 1] [:resize 1 0 0 0]]}) + objects (:objects (thf/current-page (tm/file (:situation result))))] + (doseq [grid (filter #(= :grid (:layout %)) (vals objects)) + :let [in-cells (set (mapcat :shapes (vals (:layout-grid-cells grid))))] + id (:shapes grid) + :let [child (get objects id)] + :when (not (or (:hidden child) (:layout-item-absolute child)))] + (t/is (contains? in-cells id) (:name child)))))