diff --git a/common/src/app/common/logic/swap.cljc b/common/src/app/common/logic/swap.cljc index 8b228be4ca..2c64dfceb3 100644 --- a/common/src/app/common/logic/swap.cljc +++ b/common/src/app/common/logic/swap.cljc @@ -327,13 +327,18 @@ (defn- generate-keep-orientation "Give the new head of a swap, and its subtree, the flips and the rotation of the shape it replaces, around the head's own center. They come from - its parent, as when the parent is rotated, and are not overrides." + its parent, as when the parent is rotated, and are not overrides. The + turned head takes the place of the old one at their first corner, so it + turns rigidly with its parent." [changes new-shape shape] (if-let [orient (cll/orient-like new-shape shape (gsh/shape->center new-shape))] - (pcb/update-shapes changes - (cfh/get-children-ids-with-self (pcb/get-objects changes) (:id new-shape)) - orient - {:ignore-touched true}) + (let [ids (cfh/get-children-ids-with-self (pcb/get-objects changes) (:id new-shape)) + delta (gpt/subtract (first (:points shape)) (first (:points (orient new-shape))))] + (pcb/update-shapes changes ids + (cond->> orient + (not (gpt/almost-zero? delta)) + (comp #(gsh/move % delta))) + {:ignore-touched true})) changes)) (defn- generate-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 b3f45b5a5a..659e694260 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -950,3 +950,11 @@ (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :variant-diff false :rich-variants true :layout-copies true :text true}] :ops [[:transform 3 3 0 0] [:resize 0 0 0 0] [:switch 4 0 0 0]]})))) + +(t/deftest generated-switch-in-a-turned-main-keeps-the-first-corner + ;; a head in a main turned 45 degrees switches to a wider variant; it + ;; keeps its first corner, as its copies do through sync + (t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :library-variants true :stale-libraries true + :library-depth 1 :library true :rich-variants true :library-text true + :layout-copies true :text true}] + :ops [[:rotate 1 0 0 0] [:switch 3 0 0 0]]}))))