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]]}))))