diff --git a/common/src/app/common/logic/duplicate.cljc b/common/src/app/common/logic/duplicate.cljc index 837bc4c73f..72f620befe 100644 --- a/common/src/app/common/logic/duplicate.cljc +++ b/common/src/app/common/logic/duplicate.cljc @@ -548,9 +548,20 @@ (comp (filter #(= :add-obj (:type %))) (map #(vector (:old-id %) (-> % :obj :id)))) - (:redo-changes changes))] + (:redo-changes changes)) + + objects (pcb/get-objects changes) + + ;; the new copies that no other copy holds + heads (filterv (fn [id] + (let [shape (get objects id)] + (and (ctk/instance-head? shape) + (= 1 (count (ctn/get-parent-copy-heads objects shape)))))) + (keep ids-map ids))] (-> changes + ;; a copy laid out under another parent keeps the orientation it showed + (cll/generate-keep-advanced-placement (ctn/make-container (assoc page :objects objects) :page) libraries heads) (generate-duplicate-flows shapes page ids-map) (generate-duplicate-guides shapes page ids-map delta)))) diff --git a/common/src/app/common/test_helpers/composable/gen.cljc b/common/src/app/common/test_helpers/composable/gen.cljc index 601bf7474f..c4f7cc7272 100644 --- a/common/src/app/common/test_helpers/composable/gen.cljc +++ b/common/src/app/common/test_helpers/composable/gen.cljc @@ -1140,9 +1140,21 @@ model)) (:text :text-style) (shadow/edit-text model shape (:content (n/text-edit-commit shape (:edit op) (:value op))) (some? (:typography op))) - (:duplicate :paste) (shadow/duplicate model objects id - (:objects (thf/current-page (tm/file after))) - (:new-head (n/applied-result op (tm/file before) (tm/file after)))) + (:duplicate :paste) + (let [after-objects (all-objects after) + new-head (:new-head (n/applied-result op (tm/file before) (tm/file after))) + head (get after-objects new-head) + main (get after-objects (:shape-ref head)) + model (shadow/duplicate model objects id (:objects (thf/current-page (tm/file after))) new-head)] + ;; a copy pasted on the page keeps the orientation and size it showed, + ;; which its main's need not be + (cond-> model + (and (= kind :paste) head main (:shape-ref head) + (not (get-in model [new-head :geometry-group])) + (or (not (gmt/close? (or (:transform head) (gmt/matrix)) (or (:transform main) (gmt/matrix)))) + (not (mth/close? (:width (:selrect head)) (:width (:selrect main)) 0.01)) + (not (mth/close? (:height (:selrect head)) (:height (:selrect main)) 0.01)))) + (assoc-in [new-head :geometry-group] (shadow/author-geometry head nil)))) (:swap :switch) (let [after-objects (all-objects after) old-main (get-in (cf/libraries before) [(:component-file shape) :data :components diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 0743ee0134..9aacb419f5 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -4268,3 +4268,13 @@ :ops [[:edit 1 1 1 :copy-head] [:paste 2] [:paste 0] [:sync] [:undo] [:redo]]}))) (t/is (map? (cg/run {:world [2 1 {:text true :layout :flex :layout-children true}] :ops [[:paste 1] [:paste 5] [:edit 0 0 1] [:sync]]})))) + +(t/deftest generated-a-pasted-copy-keeps-the-orientation-its-main-parent-gave-it + ;; a nested copy pasted out of a flipped or turned main keeps the + ;; orientation it showed as its own geometry + (t/is (map? (cg/run {:world [1 2 {:text false :text-styles false :layout :grid :layout-children false + :layout-item-margins false :grid-square false :grid-empty false}] + :ops [[:transform 19 17 0 4] [:detach] [:update-main] [:delete] [:restore] [:paste 14]]}))) + (t/is (map? (cg/run {:world [2 0 {:tokens false :variants true :rich-variants true :text true :layout :flex + :layout-copies false}] + :ops [[:rotate 3] [:nest 7] [:update-main] [:paste 9]]}))))