diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index d8dc915ed6..36c168ef77 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -2035,22 +2035,30 @@ libraries current-file-id 1))) (defn- settle-reset-placement - "Place a reset nested head whose geometry was overridden as an ordinary - copy of its position: its subtree takes the placement a sync of the head - that owns its ref gives. Other heads keep the placement they have." + "Place a reset nested head as an ordinary copy of its position when its + geometry was overridden, or a copy between it and the head that owns its + ref keeps its own: its subtree takes the placement a sync of that head + gives. Other heads keep the placement they have." [changes file libraries container shape-id] (let [objects (pcb/get-objects changes) shape (get objects shape-id) - parent (get objects (:parent-id shape))] + parent (get objects (:parent-id shape)) + ;; the head as it was before the reset cleared its overrides + before (ctn/get-shape container shape-id)] (if (and (= :page (:type container)) (:shape-ref parent) - (not (ctk/swapped? shape)) - (ctk/touched-group? (ctn/get-shape container shape-id) :geometry-group)) + (not (ctk/swapped? shape))) (let [container (ctn/make-container (assoc container :objects objects) :page) component (ctf/find-ref-component file container libraries shape :include-deleted? true) head (d/seek #(= (:id component) (:component-id %)) - (ctn/get-parent-copy-heads objects parent))] - (if head + (ctn/get-parent-copy-heads objects parent)) + ;; the copies from the parent up to that head + between (when head + (into [] (d/take-until #(= (:id head) (:id %))) + (cfh/get-parents-with-self objects (:id parent))))] + (if (and head + (some #(ctk/touched-group? % :geometry-group) + (cons before between))) (let [file (assoc-in file [:data :pages-index (:id container) :objects] objects) proposal (generate-sync-shape-direct (-> (pcb/empty-changes) (pcb/with-container container) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 8c620997ad..18621b92a2 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -980,3 +980,10 @@ (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout :grid :variant-diff false :rich-variants true :grid-empty true :layout-copies true :text true}] :ops [[:style 1 35 1] [:style 0 29 1]]})))) + +(t/deftest generated-reset-nested-head-keeps-the-size-its-resized-parent-gives + ;; a copy taller than its main scales a nested head set to scale + ;; vertically; resetting the head keeps the size that sync gives it + (t/is (map? (cg/run {:world [2 0 {:text true :text-styles true :layout :grid :grid-empty true}] + :ops [[:resize 0 0 0 0] [:nest 20 0 0 0] [:style 9 9 1] [:edit 20 1 1 :copy-head] + [:reset 20]]}))))