From 221973715176903222dd4f10cc7fbb11e9181bc6 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 5 Nov 2026 17:13:06 +0100 Subject: [PATCH] :bug: Keep the turn a detached copy shows when its main has another A detach makes the nested copies of the copy it detaches refer one level up. A swapped head turned 45 degrees by the position it filled becomes a copy root of its own unturned component; its turn was not its own, so the next sync turned it back to 0 and moved its children. The geometry of such a copy was made its own only under a copy parent. Under a plain parent, where a copy is placed freely, the copy now keeps as its own an orientation or a size that differs from its main turned like that parent. The orientation is compared by composing the axes of the plain parent, of the main's parent and of the main, without placing anything, so a main at the root of its page, whose parent is the page's 0x0 frame, compares right too; the size is compared with the main's. The model expects the same. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 19.758 | 0.56 | | edit-through-a-chain-of-dependents | 68.931 | 41.031 | 0.60 | | library-update-into-copies | 83.083 | 51.567 | 0.62 | | main-edit-among-many-shapes | 4.837 | 2.314 | 0.48 | | main-edit-into-10-copies | 1.79 | 0.933 | 0.52 | | main-edit-into-100-copies | 15.415 | 9.007 | 0.58 | | main-edit-into-1000-copies | 153.086 | 90.173 | 0.59 | | variant-switch-into-copies | 32.052 | 21.637 | 0.68 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 33 +++++++++++++++---- .../logic/composable_gen_test.cljc | 18 ++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index d4c44de359..345cbf15ef 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -1788,11 +1788,29 @@ changes))) changes ids)) +(defn- turned-like-parent? + "Whether `shape` has the size of `main` and the orientation `main` takes + when turned from `main-parent` to `parent`, wherever each one is. A + main at the root of its page has an unturned parent." + [shape main main-parent parent] + (let [main-parent (when-not (cfh/root? main-parent) main-parent) + flip? (fn [key] (odd? (count (filter key [main main-parent parent]))))] + (and (mth/close? (-> shape :selrect :width) (-> main :selrect :width)) + (mth/close? (-> shape :selrect :height) (-> main :selrect :height)) + (gmt/close? (axes-matrix shape) + (gmt/multiply (axes-matrix parent) + (gmt/inverse (axes-matrix main-parent)) + (axes-matrix main))) + (= (boolean (:flip-x shape)) (flip? :flip-x)) + (= (boolean (:flip-y shape)) (flip? :flip-y))))) + (defn generate-keep-advanced-placement "Make authored the geometry of the copy shapes `ids`, whose references advanced, when their next sync would place them elsewhere: their copy - parent keeps overrides that the new main lacks. Parents come before - their children, so each child is checked in its parent's settled frame." + parent keeps overrides that the new main lacks. Under a plain parent a + copy is placed freely, and only its orientation and size follow its + main, turned like that parent. Parents come before their children, so each child is checked in + its parent's settled frame." [changes container libraries ids] (reduce (fn [changes id] @@ -1804,11 +1822,14 @@ :include-deleted? true :with-context? true) main-objects (:objects (:container (meta main))) main-parent (get main-objects (:parent-id main))] - (if (and (some? (:shape-ref parent)) (some? main-parent) + (if (and (some? main) (not (ctk/touched-group? shape :geometry-group)) - (not (close-geometry? shape (get (placed-like main-objects main-parent parent - (authored-constraints objects [id])) - (:id main))))) + (if (some? (:shape-ref parent)) + (and (some? main-parent) + (not (close-geometry? shape (get (placed-like main-objects main-parent parent + (authored-constraints objects [id])) + (:id main))))) + (not (turned-like-parent? shape main main-parent parent)))) (pcb/update-shapes changes [id] #(update % :touched ctk/set-touched-group :geometry-group) {:ignore-touched true}) changes))) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 522b1c0fe8..76de37faa0 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1134,3 +1134,21 @@ :grid-square false :library true :rich-variants true :layout-children false :grid-empty false :layout-copies true :text true}] :ops [[:style 16 8 1] [:edit 11 11 0 0] [:resize 0 0 0 0] [:update-main 4 0 0 0]]})))) + +(t/deftest generated-detach-keeps-the-turn-a-swapped-head-had-from-its-position + ;; a swapped head turned by its position becomes a copy root of its own + ;; unturned component when its copy root is detached; it keeps the turn + (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles true :layout nil :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children false :grid-empty false :layout-copies true :text true}] + :ops [[:swap 15 0 0 0] [:nest 7 0 0 0] [:edit 3 0 1 1] [:update-main 3] + [:text-style 18 0 1] [:duplicate 0 0 0 0] [:nest 15 0 0 0] [:switch 6 0 0 0] + [:rotate 19 0 0 0] [:detach 3 0 0 0]]})))) + +(t/deftest generated-detach-leaves-a-nested-copy-that-only-takes-its-parents-turn + ;; a turned copy root is detached; its nested copy, whose main sits at the + ;; root of its page, only shows the turn of its now plain parent + (t/is (map? (cg/run {:world [2 2 {:text true :text-styles true :layout nil :layout-children false + :layout-item-margins false :grid-square false :grid-empty false}] + :ops [[:delete 0] [:restore 0] [:undo 0 0 0 0] [:delete 11] [:restore 11] + [:delete 1 0 0 0] [:delete 3 0 0 0] [:rotate 4 0 0 0] [:detach 11 0 0 0]]}))))