From 026819056c7c44802cfa61e7589d25c34d861d55 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sun, 1 Nov 2026 06:36:39 +0100 Subject: [PATCH] :bug: Push a swap into its main without the turn the copy inherits A nested copy turned with the main that holds it swaps a child, and update-main pushes that child into its own unturned main. Update-main turns paired shapes back to the main's orientation, but add-shape-to-main cloned the pushed child as it was in the copy, so the main took the copy's turn and its copies turned twice. A pushed shape and its placement reference now take the same inherited turn before they are repositioned into the main. The model leaves the inherited turn out of a pushed swap's geometry likewise. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 19.463 | 0.55 | | edit-through-a-chain-of-dependents | 68.931 | 38.1 | 0.55 | | library-update-into-copies | 83.083 | 46.7 | 0.56 | | main-edit-among-many-shapes | 4.837 | 2.227 | 0.46 | | main-edit-into-10-copies | 1.79 | 1.064 | 0.59 | | main-edit-into-100-copies | 15.415 | 10.225 | 0.66 | | main-edit-into-1000-copies | 153.086 | 101.264 | 0.66 | | variant-switch-into-copies | 32.052 | 20.333 | 0.63 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 12 +++++++++--- .../test/common_tests/logic/composable_gen_test.cljc | 7 +++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 0b654fbb42..2109d034c2 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -1101,7 +1101,7 @@ "Add to the main shape `parent-main`, at `index`, a copy of `child-inst`, a child of the copy shape that pairs with it; `child-inst` then refers to the new main shape." - [changes {:keys [container main-container root-inst root-main libraries added synced-ids]} + [changes {:keys [container main-container root-inst root-main libraries added synced-ids inherited-turn]} parent-main child-inst index] (shape-log :info (:id child-inst) container :msg (str "ADD " (shape-label child-inst main-container))) @@ -1119,6 +1119,12 @@ (ctf/find-content-ref-shape nil container libraries child-inst :include-deleted? true :with-context? true)) + ;; copy shapes in the main's orientation, without the turn the copy inherits + in-main (fn [shape] + (-> (cond-> shape (some? inherited-turn) inherited-turn) + (reposition-shape (cond-> root-inst (some? inherited-turn) inherited-turn) + root-main))) + ;; The parent's inverse sync already pushed its geometry. Compare ;; against that frame, rather than its original container value. placement-container @@ -1126,12 +1132,12 @@ content-main (assoc-in [:objects (:id parent-main)] (-> (ctn/get-shape container (:parent-id child-inst)) - (reposition-shape root-inst root-main) + (in-main) (assoc :id (:id parent-main) :shape-ref (:shape-ref parent-main))))) update-new-shape (fn [new-shape original-shape] - (cond-> (reposition-shape new-shape root-inst root-main) + (cond-> (in-main new-shape) (and (= (:id original-shape) (:id child-inst)) (ctk/swapped? child-inst) (not swap-in-copy?)) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 8bda203af6..b8c64326c1 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -901,3 +901,10 @@ :when (not= :grid (:layout shape))] (t/is (empty? (:layout-grid-cells shape)) (:name shape)) (t/is (not (contains? (:touched shape) :layout-grid-cells)) (:name shape))))) + +(t/deftest generated-update-main-pushes-a-swap-in-its-mains-orientation + ;; a nested copy turned with the main that holds it swaps a child and + ;; pushes it into its own unturned main, which takes it unturned + (t/is (map? (cg/run {:world [2 1 {:variants true :text-styles true :library true :rich-variants true + :layout-copies true :text true}] + :ops [[:swap 6 0 0 0] [:transform 17 3 0 0] [:swap 9 0 0 0] [:edit 0 0 1 1] [:update-main 0]]}))))