diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 53e5a918ff..e8e68f51da 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -2023,13 +2023,31 @@ changes)) changes))) +(defn- reset-layout-item + "Give a reset head the layout item values it inherits: those of its ref + when its parent is the copy of the ref's layout parent. Sync passes them + from parent to children, so the reset of the head alone keeps them." + [changes file libraries container shape-id] + (let [objects (pcb/get-objects changes) + shape (get objects shape-id) + parent (get objects (:parent-id shape)) + ref (when (and (:layout parent) (:shape-ref parent)) + (ctf/find-ref-shape file (assoc container :objects objects) libraries shape + :include-deleted? true :with-context? true)) + ref-parent (get-in (meta ref) [:container :objects (:parent-id ref)])] + (if (and ref (:layout ref-parent) (= (:id ref-parent) (:shape-ref parent))) + (pcb/update-shapes changes [shape-id] #(propagate-attrs % ref layout-child-attrs false) + {:ignore-touched true}) + changes))) + (defn generate-reset-component "Reset the copy head to its near main. A swapped head turns back into the component of the main shape it refers to, keeping its id. A nested head - also takes its position's placement." + also takes its position's placement and inherited layout item values." [changes file-full libraries container id] (-> changes (pcb/with-container container) (pcb/with-objects (:objects container)) (generate-sync-shape-direct file-full libraries container id true) - (settle-reset-placement file-full libraries container id))) + (settle-reset-placement file-full libraries container id) + (reset-layout-item file-full libraries container id))) diff --git a/common/test/common_tests/logic/comp_reset_test.cljc b/common/test/common_tests/logic/comp_reset_test.cljc index c9eb24e5af..1831be64b1 100644 --- a/common/test/common_tests/logic/comp_reset_test.cljc +++ b/common/test/common_tests/logic/comp_reset_test.cljc @@ -673,3 +673,11 @@ (t/is (map? (cg/run {:world [2 0 {:library true :stale-libraries true :library-dependency true :library-text true}] :ops [[:library-transform 14 3 0 0] [:edit 13 1 1 :copy-head] [:reset 13]]})))) + +(t/deftest reset-restores-a-nested-copys-inherited-layout-item-values + ;; The nested head's margin type overrides the one its flex position inherits. + (t/is (map? (cg/run {:world [2 1 {:variants true :rich-variants true :text true :text-styles true + :library-variants true :stale-libraries true :library-depth 1 + :library true :library-text true :layout :flex + :layout-children true :layout-copies true}] + :ops [[:style 11 27 1] [:reset 14 0 0 0] [:undo] [:redo]]}))))