From 7aa788c6e5a391a8ad96bdd31c3dab8d56d0b4f8 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 18 Nov 2026 00:16:25 +0100 Subject: [PATCH] :bug: Give a re-headed swapped copy its new main's placement A swapped nested head pasted out of every copy level becomes a plain copy of the component it shows. It kept as overrides the placement that differs from its new main, but left the rest as it was: a nil constraint, the default of its old board, kept meaning something else at the page root while its main states `:left`, so it no longer matched its main (F592). Users reach it by copying such a copy and pasting it. `rehead-swapped` now gives the placement attributes it does not override the new main's values. Found by a fresh gate round (seed 20261117, library property). Test (swap-group-test, fails before the fix): `paste-gives-a-swapped-head-the-placement-of-its-new-main`. Benchmark (bench-components, alone): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+---------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 20.608 | 21.876 | 0.59 | | edit-through-a-chain-of-dependents | 68.931 | 42.175 | 44.133 | 0.61 | | library-update-into-copies | 83.083 | 50.77 | 52.63 | 0.61 | | main-edit-among-many-shapes | 4.837 | 2.352 | 2.51 | 0.49 | | main-edit-into-10-copies | 1.79 | 1.043 | 1.087 | 0.58 | | main-edit-into-100-copies | 15.415 | 10.185 | 10.428 | 0.66 | | main-edit-into-1000-copies | 153.086 | 101.226 | 105.622 | 0.66 | | variant-switch-into-copies | 32.052 | 22.621 | 23.491 | 0.71 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/instances.cljc | 13 ++++++++++++- common/test/common_tests/logic/swap_group_test.cljc | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/logic/instances.cljc b/common/src/app/common/logic/instances.cljc index 18bd2c21f3..8b4bdb0891 100644 --- a/common/src/app/common/logic/instances.cljc +++ b/common/src/app/common/logic/instances.cljc @@ -181,8 +181,19 @@ (when (and (contains? placement-groups group) (not= (value shape attr) (value main attr))) group)))) + (keys ctk/sync-attrs)) + ;; the placement it does not override is the new main's, as it shows + ;; it in its old position + followed (into [] + (filter (fn [attr] + (let [group (ctk/resolve-sync-group (:type shape) attr)] + (and (contains? placement-groups group) + (not (contains? groups group)) + (not (ctk/touched-group? shape group)))))) (keys ctk/sync-attrs))] - (cond-> (-> shape + (cond-> (-> (reduce (fn [shape attr] + (if (nil? (get main attr)) (dissoc shape attr) (assoc shape attr (get main attr)))) + shape followed) (assoc :shape-ref (:id main)) (ctk/remove-swap-group)) (seq groups) (update :touched (fnil into #{}) groups)))) diff --git a/common/test/common_tests/logic/swap_group_test.cljc b/common/test/common_tests/logic/swap_group_test.cljc index 9a910781b9..41a153b334 100644 --- a/common/test/common_tests/logic/swap_group_test.cljc +++ b/common/test/common_tests/logic/swap_group_test.cljc @@ -374,6 +374,18 @@ (t/is (not (ctk/swapped? head))) (t/is (= (thi/id :heart-rect) (:shape-ref child))))) +(t/deftest paste-gives-a-swapped-head-the-placement-of-its-new-main + ;; :copy-star shows the default constraint of its board, which :heart-main + ;; states explicitly; out of its copy it overrides none, so it takes the + ;; main's as it is, which keeps meaning the same at the page root + (let [file (-> (setup) + (ths/update-shape :heart-main :constraints-h :left)) + objects (copy-objects file :copy-star) + head (get objects (thi/id :copy-star))] + (t/is (= (thi/id :heart-main) (:shape-ref head))) + (t/is (= :left (:constraints-h head))) + (t/is (not (contains? (:touched head) :constraints-group))))) + (t/deftest paste-advances-a-deeper-swapped-head-by-position (let [file (setup-two-levels) dot-id (:id (first-child file :outer-star)) @@ -458,7 +470,6 @@ (t/is (= (thi/id :dot-main) (:shape-ref (get objects (:id dot))))) (t/is (= (thi/id :dot-heart) (:shape-ref (get objects (:id heart))))))) - (t/deftest duplicate-keeps-the-swap (let [file (-> (setup) (tho/duplicate-shape :copy)