diff --git a/common/src/app/common/test_helpers/composable/gen.cljc b/common/src/app/common/test_helpers/composable/gen.cljc index 8e07ebc58b..44483934c1 100644 --- a/common/src/app/common/test_helpers/composable/gen.cljc +++ b/common/src/app/common/test_helpers/composable/gen.cljc @@ -1004,6 +1004,7 @@ (shadow/parent-orientation (all-objects situation) (all-objects settled)) (shadow/layout-released (all-objects situation) (all-objects settled)) (shadow/sync-scaled-heads (all-objects situation) (all-objects settled)) + (shadow/radius-orientation (all-objects situation) (all-objects settled)) (settle-model settled true)) all (into (set (synchronizable-components situation)) (r/pending-components situation)) full-before (r/settle situation all) @@ -1085,10 +1086,11 @@ (:transform :library-transform) (n/geometry-modifiers shape (:action op) (:value op))) parent (get objects (:parent-id shape)) ;; the mask of a group passes its change to the group and back, so - ;; the tree would apply it twice; only its group places it + ;; the tree would apply it twice; its group takes the change, which + ;; a layout around the group may place again mask? (and (:masked-group parent) (= (:id shape) (first (:shapes parent)))) - tree (when-not mask? (gm/set-objects-modifiers {(:id shape) {:modifiers modifiers}} objects))] - (gsh/transform-shape shape (if mask? modifiers (get-in tree [(:id shape) :modifiers]))))) + tree (gm/set-objects-modifiers {(if mask? (:id parent) (:id shape)) {:modifiers modifiers}} objects)] + (gsh/transform-shape shape (get-in tree [(if mask? (:id parent) (:id shape)) :modifiers])))) (defn- kind-file "The file an operation edits: the library `library-id`, or the current one." @@ -1141,8 +1143,13 @@ ;; a move resets the shape's constraints to its new parent's defaults, ;; which an override of them now holds; a move keeps where the shape ;; shows, so the geometry it authored is now that, in its new parent - :move (let [moved (get (all-objects after) id)] + :move (let [moved (get (all-objects after) id) + parent (get objects (tm/target-shape-id before (:into op)))] (cond-> model + ;; as a nest: a shape moved into a blocked parent is blocked + (:blocked parent) + (shadow/edit shape :blocked true) + (get-in model [id :constraints-group]) (assoc-in [id :constraints-group] (shadow/values moved :constraints-group)) @@ -1159,7 +1166,12 @@ (let [after-objects (all-objects after) new-head (:new-head (n/applied-result op (tm/file before) (tm/file after))) head (get after-objects new-head) - main (get after-objects (:shape-ref head)) + ;; its main as the file accepted it, which a stale library's + ;; loaded version need not be + main (or (when head + (get (into {} (mapcat cf/object-trees) (vals (cf/reference-libraries after head))) + (:shape-ref head))) + (get after-objects (:shape-ref head))) model (shadow/duplicate model objects id (:objects (thf/current-page (tm/file after))) new-head)] ;; a copy pasted on the page keeps the geometry it showed: what it ;; authored, now where it lands, and the orientation and size another @@ -1365,7 +1377,8 @@ (not (#{:undo :redo} kind)) (-> (shadow/parent-orientation (all-objects situation) (all-objects after)) (shadow/layout-released (all-objects situation) (all-objects after)) - (shadow/sync-scaled-heads (all-objects situation) (all-objects after)))) + (shadow/sync-scaled-heads (all-objects situation) (all-objects after)) + (shadow/radius-orientation (all-objects situation) (all-objects after)))) next-model (settle-model next-model after (empty? (r/pending-components after))) meaningful (not (oracle/equivalent? (oracle/design-snapshot situation {:free-head-placement false}) (oracle/design-snapshot after {:free-head-placement false}))) diff --git a/common/src/app/common/test_helpers/composable/shadow.cljc b/common/src/app/common/test_helpers/composable/shadow.cljc index c89054bd1a..b5bfe7a003 100644 --- a/common/src/app/common/test_helpers/composable/shadow.cljc +++ b/common/src/app/common/test_helpers/composable/shadow.cljc @@ -646,6 +646,19 @@ model model)) +(defn radius-orientation + "A flip moves a shape's radius tokens with the corners they apply to, so + the radius a copy authored names them as it shows them after it." + [model before after] + (reduce-kv + (fn [result id groups] + (let [old (get before id) + new (get after id)] + (if (and old new (get-in groups [:radius-group :applied-tokens])) + (update-in result [id :radius-group :applied-tokens] ctsr/tokens-in-orientation old new) + result))) + model model)) + (defn parent-orientation "Authored child geometry moves with its parent's orientation. Compare the parent frames, without reading the child's resulting geometry." diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 21acba9213..65858e96bb 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2495,6 +2495,36 @@ :ops [[:variant-property 0 9 3 0] [:switch 4] [:combine 2] [:switch 8] [:style 11 7 1] [:update-main 2 0 0 0]]})))) +(t/deftest a-pasted-copy-compares-with-the-main-the-file-accepted + ;; the library widened a main the stale file has not accepted: a copy + ;; pasted from it shows the accepted size, which is no override + (t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :library-variants true :stale-libraries true + :layout nil :layout-item-margins false :grid-square false :library-depth 2 + :library true :rich-variants true :layout-children false :library-text true + :grid-empty false :layout-copies true :text true}] + :ops [[:library-delete 0] [:library-sync] [:library-restore 0] [:library-sync] + [:library-transform 0 1 4 0] [:paste 23 0 0 0]]})))) + +(t/deftest moving-the-mask-of-a-group-a-flex-places-leaves-it-in-place + ;; the mask moves its group, which the flex puts back in its place + (t/is (map? (cg/run {:world [2 1 {:variants true :rich-variants true :text true :layout :flex + :layout-copies true :layout-children true}] + :ops [[:add-child 0] [:structure 0 0 0] [:nest 5 0 0 0] [:add-child 0 0 0 0] + [:add-child 6] [:structure 14 1 0] [:transform 6 0 0 12]]})))) + +(t/deftest a-copy-moved-into-a-blocked-board-is-blocked + ;; as a nest into a blocked parent, a move blocks the copy, an override + (t/is (map? (cg/run {:world [3 2 {:text true :text-styles true :layout nil :layout-children false + :layout-item-margins false :grid-square false :grid-empty false}] + :ops [[:style 0 2 1] [:remove-child 0 0 0 0] [:move 11 0 0 0]]})))) + +(t/deftest a-flip-moves-the-radius-tokens-a-copy-authored + ;; a copy that set one corner by hand keeps its radius tokens on the + ;; corners they apply to once a flip mirrors it + (t/is (map? (cg/run {:world [2 0 {:tokens true :variants true :rich-variants true :text true :layout nil + :layout-copies true}] + :ops [[:apply-token 10 0] [:style 10 3 0 1] [:transform 5 16 0 0]]})))) + (t/deftest a-token-edit-keeps-the-square-corner-of-a-mirrored-copy ;; a copy mirrored horizontally takes its main's radius tokens on the ;; corners it shows them on, so a token edit leaves the corner its main