diff --git a/common/src/app/common/types/file.cljc b/common/src/app/common/types/file.cljc index 07873237a8..01d0976341 100644 --- a/common/src/app/common/types/file.cljc +++ b/common/src/app/common/types/file.cljc @@ -550,13 +550,15 @@ [remote-shape component-container component-file] (if (some? remote-shape) [remote-shape component-container component-file] - ;; If not found, try the case of this being a fostered or swapped children - (let [head-instance (ctn/get-head-shape (:objects container) shape) - component-file (get-in libraries [(:component-file head-instance) :data]) - head-component (ctkl/get-component component-file (:component-id head-instance) true) - remote-shape' (get-ref-shape component-file head-component shape) - component-container' (get-component-container component-file head-component)] - [remote-shape' component-container' component-file]))] + ;; A fostered or swapped child refers to the main of a nested + ;; head, tried from the nearest one up + (some (fn [head] + (let [component-file (get-in libraries [(:component-file head) :data]) + head-component (ctkl/get-component component-file (:component-id head) true) + remote-shape' (get-ref-shape component-file head-component shape)] + (when (some? remote-shape') + [remote-shape' (get-component-container component-file head-component) component-file]))) + (reverse (ctn/get-parent-heads (:objects container) shape))))] (if (nil? remote-shape) nil diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 77279eb1f5..b32ed9aedb 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1178,3 +1178,12 @@ :library true :rich-variants true :layout-children true :library-text true :grid-empty true :layout-copies true :text true}] :ops [[:style 13 29 1] [:rotate 6 0 0 0]]})))) + +(t/deftest generated-switch-finds-the-main-of-a-copy-in-a-swapped-copy + ;; a switch of a nested copy inside a swapped copy, itself inside a copy of + ;; a deleted component, carries its child's text override from the main + ;; the swapped copy holds + (t/is (map? (cg/run {:world [2 1 {:variants true :text-styles true :layout nil :layout-item-margins false + :grid-square false :library true :rich-variants true :layout-children false + :grid-empty false :layout-copies true :text true}] + :ops [[:nest 6 0 0 0] [:text 6 0 0 0] [:delete 6 0 0 0] [:swap 6 0 0 0] [:switch 0 0 0 0]]}))))