From c09fb3d26c9e355382001206f37f7c6dec80b019 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sat, 31 Oct 2026 22:52:41 +0100 Subject: [PATCH] :bug: Keep a copy child made absolute where its layout placed it A copy child taken out of its layout's flow stays where the layout put it, which can differ from its main's place when the copy has its own layout values. Making it absolute now marks its geometry as an override too, so sync keeps that place instead of moving it to the main's. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+--------+-------| | deepest-edit-through-three-levels | 35.215 | 18.081 | 0.51 | | edit-through-a-chain-of-dependents | 68.931 | 35.42 | 0.51 | | library-update-into-copies | 83.083 | 45.335 | 0.55 | | main-edit-among-many-shapes | 4.837 | 2.3 | 0.48 | | main-edit-into-10-copies | 1.79 | 0.905 | 0.51 | | main-edit-into-100-copies | 15.415 | 8.714 | 0.57 | | main-edit-into-1000-copies | 153.086 | 88.228 | 0.58 | | variant-switch-into-copies | 32.052 | 20.752 | 0.65 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/types/container.cljc | 12 ++++++++++-- .../common_tests/logic/comp_touched_test.cljc | 17 +++++++++++++++++ .../common_tests/logic/composable_gen_test.cljc | 9 +++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/types/container.cljc b/common/src/app/common/types/container.cljc index 493a87336d..46d3a2de23 100644 --- a/common/src/app/common/types/container.cljc +++ b/common/src/app/common/types/container.cljc @@ -710,12 +710,20 @@ (not (and ignore-geometry is-geometry?))) ;; a text's content touches the groups of what the edit changes - ;; in it, and none when it changes nothing a copy can override + ;; in it, and none when it changes nothing a copy can override; a + ;; copy child taken out of its layout's flow keeps the place the + ;; layout gave it, as its own geometry content-groups (when (and may-touch? group (not equal?)) - (if (and (= type :text) (= attr :content)) + (cond + (and (= type :text) (= attr :content)) (let [groups (cttx/changed-groups (:content shape) val)] (cond-> groups (seq groups) (conj group))) + + (and (= attr :layout-item-absolute) (true? val)) + #{group :geometry-group} + + :else #{group})) token-groups diff --git a/common/test/common_tests/logic/comp_touched_test.cljc b/common/test/common_tests/logic/comp_touched_test.cljc index ae8dc29763..ce0d5b6429 100644 --- a/common/test/common_tests/logic/comp_touched_test.cljc +++ b/common/test/common_tests/logic/comp_touched_test.cljc @@ -351,3 +351,20 @@ file' (thf/apply-changes file changes)] (t/is (= #{:shadow-group group} (:touched (ths/get-shape file' :copy-child))) (name attr))))) + +(t/deftest a-copy-child-made-absolute-keeps-its-place-as-an-override + (let [file (-> (thf/sample-file :file1) + (tho/add-simple-component-with-copy :component1 :main-root :main-child :copy-root + :copy-root-params {:children-labels [:copy-child]}) + (ths/update-shape :main-root :layout :flex) + (ths/update-shape :copy-root :layout :flex)) + page (thf/current-page file) + copy-child (ths/get-shape file :copy-child) + changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(:id copy-child)} + #(assoc % :layout-item-absolute true) + (:objects page) + {}) + file' (thf/apply-changes file changes)] + (t/is (= #{:layout-item-absolute :geometry-group} + (:touched (ths/get-shape file' :copy-child)))))) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 5948466ad0..76dcbf4219 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -851,3 +851,12 @@ [:undo] [:redo] [:reset 0] [:sync 1] [:switch 1 0 0 0] [:rotate 1 0 0 0] [:duplicate 0 0 0 0] [:reset 2 0 0 0] [:redo 0 0 0 0]]})))) + +(t/deftest generated-copy-child-made-absolute-keeps-its-own-layouts-place + ;; the copy's own gap places its Rectangle, which stays there as absolute + (let [result (cg/run {:world [2 0 {:layout :grid :grid-square true :layout-children true :layout-copies true}] + :ops [[:style 2 11 1] [:style 6 35 1]]}) + objects (:objects (thf/current-page (tm/file (:situation result)))) + child (some #(when (:layout-item-absolute %) %) (vals objects))] + (t/is (:shape-ref child)) + (t/is (contains? (:touched child) :geometry-group))))