diff --git a/common/src/app/common/test_helpers/composable/gen.cljc b/common/src/app/common/test_helpers/composable/gen.cljc index 237890265f..601bf7474f 100644 --- a/common/src/app/common/test_helpers/composable/gen.cljc +++ b/common/src/app/common/test_helpers/composable/gen.cljc @@ -405,6 +405,13 @@ :nest (and (top-copy shape) (not (overridden (:id shape)))) ;; a shape a main holds, other than its root: a plain shape ;; or a nested copy head, which no copy around it holds + ;; a top copy, or a plain shape a main holds: nothing in it + ;; leaves a copy level, so the clipboard advances no ref + :paste (and (< (count objects) (get situation :shape-budget 120)) + (or (top-copy shape) + (and (nil? (:shape-ref shape)) + (not (ctk/main-instance? shape)) + (some ctk/main-instance? (cfh/get-parents objects (:id shape)))))) :rename (and (ctk/main-instance? shape) (not (:variant-id shape)) (live-component shape)) :annotate (and (ctk/main-instance? shape) (live-component shape)) @@ -886,6 +893,7 @@ :remove-child (n/remove-child target) :duplicate (n/duplicate target) (:nest :move) (n/nest-copy target (constantly (get-in selected [:parent :id]))) + :paste (n/paste-to-root target) :rename (n/rename-component target (first (nth rename-values (mod (or (nth tuple 3 nil) 0) (count rename-values))))) :annotate (n/annotate-component target (nth annotations (mod (or (nth tuple 3 nil) 0) @@ -1132,9 +1140,9 @@ model)) (:text :text-style) (shadow/edit-text model shape (:content (n/text-edit-commit shape (:edit op) (:value op))) (some? (:typography op))) - :duplicate (shadow/duplicate model objects id - (:objects (thf/current-page (tm/file after))) - (:new-head (n/applied-result op (tm/file before) (tm/file after)))) + (:duplicate :paste) (shadow/duplicate model objects id + (:objects (thf/current-page (tm/file after))) + (:new-head (n/applied-result op (tm/file before) (tm/file after)))) (:swap :switch) (let [after-objects (all-objects after) old-main (get-in (cf/libraries before) [(:component-file shape) :data :components @@ -1654,7 +1662,7 @@ (def structure-kinds [:edit :reset :update-main :detach :sync :undo :redo :text :text-style :add-child :remove-child :duplicate :nest :delete :restore :resize :rotate :style :transform - :grid-direction :grid-cell :move :rename :annotate]) + :grid-direction :grid-cell :move :rename :annotate :paste]) (def structure-program-gen (gen/let [components (gen/choose 2 3) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 35e8215cc7..0743ee0134 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -4260,3 +4260,11 @@ (t/is (map? (cg/run {:world [1 0 {:variants true :rich-variants true :text true :layout :grid :layout-copies false :layout-children true}] :ops [[:add-child] [:style 0 35 1] [:add-child] [:add-child 8] [:structure 12 0 3]]})))) + +(t/deftest generated-pastes-carry-a-copy-and-its-overrides-to-the-page + ;; a pasted top copy keeps the overrides of the copy it came from; a + ;; pasted shape a main holds is a plain shape + (t/is (map? (cg/run {:world [2 1 {:text true :layout nil}] + :ops [[:edit 1 1 1 :copy-head] [:paste 2] [:paste 0] [:sync] [:undo] [:redo]]}))) + (t/is (map? (cg/run {:world [2 1 {:text true :layout :flex :layout-children true}] + :ops [[:paste 1] [:paste 5] [:edit 0 0 1] [:sync]]}))))