From a9cce26fe02bdfc582ff23c74da7442c72ae8e61 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 13 Nov 2026 21:21:20 +0100 Subject: [PATCH] :bug: Keep the orientation a pasted copy showed as its own geometry A nested copy inside a flipped or turned main shows the orientation its parent gives it. Copied and pasted elsewhere, it kept that orientation without marking its geometry, so the next sync turned it back to its main's with no edit. Each new top copy of a paste or duplicate now goes through the check a detached copy does: when it is not oriented and sized as its main turned like its new parent, its geometry is marked as its own. The harness model authors the same geometry. Benchmark (lower quantile, ms): | world | baseline | now | mean | ratio | |------------------------------------+----------+---------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 22.546 | 22.997 | 0.64 | | edit-through-a-chain-of-dependents | 68.931 | 42.115 | 43.255 | 0.61 | | library-update-into-copies | 83.083 | 52.064 | 54.230 | 0.63 | | main-edit-among-many-shapes | 4.837 | 2.409 | 2.585 | 0.50 | | main-edit-into-10-copies | 1.79 | 1.072 | 1.139 | 0.60 | | main-edit-into-100-copies | 15.415 | 10.340 | 10.963 | 0.67 | | main-edit-into-1000-copies | 153.086 | 105.617 | 109.281 | 0.69 | | variant-switch-into-copies | 32.052 | 22.217 | 22.754 | 0.69 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/duplicate.cljc | 13 ++++++++++++- .../common/test_helpers/composable/gen.cljc | 18 +++++++++++++++--- .../logic/composable_gen_test.cljc | 10 ++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) 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]]}))))