diff --git a/common/src/app/common/logic/duplicate.cljc b/common/src/app/common/logic/duplicate.cljc index ac69cddd1f..b9acaf490a 100644 --- a/common/src/app/common/logic/duplicate.cljc +++ b/common/src/app/common/logic/duplicate.cljc @@ -453,16 +453,22 @@ advance-shape (fn [level-delta objects shape] (let [new-shape-ref (ctf/advance-shape-ref file page libraries shape level-delta {:include-deleted? true})] - (cond-> objects - (and (some? new-shape-ref) (not= new-shape-ref (:shape-ref shape))) - (-> (assoc-in [(:id shape) :shape-ref] new-shape-ref) - (assoc-in [(:id shape) :touched] - (set/union + (if (and (some? new-shape-ref) (not= new-shape-ref (:shape-ref shape))) + (let [;; the references between the shape and its new one + skipped (->> (ctf/get-ref-chain-until-target-ref container libraries shape new-shape-ref) + rest + (remove #(= (:id %) new-shape-ref))) + touched (set/union (or (:touched shape) #{}) (cli/inherited-touched shape - (ctf/get-touched-from-ref-chain-until-target-ref - container libraries shape new-shape-ref)))))))) + (into #{} (mapcat :touched) skipped)))] + (-> (assoc-in objects [(:id shape) :shape-ref] new-shape-ref) + ;; a shape with no touched group has no touched set + (update (:id shape) #(if (seq touched) + (assoc % :touched touched) + (dissoc % :touched))))) + objects))) detach-copy (fn [objects shape] (reduce #(update %1 %2 ctk/detach-shape) objects diff --git a/common/test/common_tests/logic/copying_and_duplicating_test.cljc b/common/test/common_tests/logic/copying_and_duplicating_test.cljc index 404ab7a991..e842b16295 100644 --- a/common/test/common_tests/logic/copying_and_duplicating_test.cljc +++ b/common/test/common_tests/logic/copying_and_duplicating_test.cljc @@ -8,6 +8,7 @@ (:require [app.common.files.changes :as ch] [app.common.files.changes-builder :as pcb] + [app.common.files.helpers :as cfh] [app.common.geom.point :as gpt] [app.common.logic.duplicate :as cld] [app.common.logic.libraries :as cll] @@ -157,3 +158,26 @@ ;; - Change color of the copy you duplicated from, and check that it's NOT PROPAGATED. (tho/update-bottom-color :group-3 "#333333" :propagate-fn propagate-all-component-changes) (validate #(t/is (= (count-shapes % "rect-simple-1" "#333333") 2))))) + +(t/deftest a-pasted-nested-copy-takes-only-the-overrides-of-the-references-it-skips + ;; the nested copy of :c2 that a copy of :c3 holds, pasted out of it, refers + ;; to the main of :c2, whose nested rect overrides its fill; the pasted rect + ;; shows that fill without overriding it, and keeps no touched set + (let [file (-> (thf/sample-file :file1) + (tho/add-two-levels-nested-component-with-copy + :c1 :main1-root :main1-child + :c2 :main2-root :nested-head1 + :c3 :main3-root :nested-head2 :nested-subhead2 + :copy3 + :nested-head1-params {:children-labels [:nested-rect1]} + :copy2-root-params {:children-labels [:copy-head2 :copy-subhead2 :copy-rect]}) + (tho/update-color :nested-rect1 "#111111")) + page (thf/current-page file) + objects (:objects page) + ids (cfh/get-children-ids-with-self objects (thi/id :copy-head2)) + copied (cld/advance-copied-objects file page {(:id file) file} + (select-keys objects ids) [(thi/id :copy-head2)]) + rect (get copied (thi/id :copy-rect))] + (t/is (= #{:fill-group} (:touched (get objects (thi/id :nested-rect1))))) + (t/is (= (thi/id :nested-rect1) (:shape-ref rect))) + (t/is (not (contains? rect :touched)) (pr-str (:touched rect))))) diff --git a/common/test/common_tests/logic/golden_master.edn b/common/test/common_tests/logic/golden_master.edn index a1ac903643..ec6996f2b2 100644 --- a/common/test/common_tests/logic/golden_master.edn +++ b/common/test/common_tests/logic/golden_master.edn @@ -57,7 +57,7 @@ {:transcript "create-component {:component \"main\", :id sync-main-component}\n add-tokens {:tokens [[\"radius.s\" 10] [\"radius.l\" 30]]}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n one-of -> skip\n apply-token {:target #fn, :token-name \"radius.l\", :value 30}\n test\n unapply-token {:target #fn, :token-name \"radius.l\"}", :states ["2bcdf6d40b47eea3" "3dabf53ca39c6d4d" "af5ac8a5ea672f3b"]} {:transcript "create-component {:component \"main\", :id sync-main-component}\n add-tokens {:tokens [[\"radius.s\" 10] [\"radius.l\" 30]]}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n one-of -> skip\n apply-token {:target #fn, :token-name \"radius.l\", :value 30}\n test\n one-of -> skip", :states ["2bcdf6d40b47eea3" "0d34ab60457acb76"]}] :az - [{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-nested-component {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n make-nested-component {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n paste-to-root {:target #fn, :new-head 5}\n test\n change-property {:target #fn, :property :fills, :value \"#ff0000\"}", :states ["c8c845596f55aa86" "1d1b26cfc6a035e4" "cdcb72926d45d3db" "c6ccfcd10b8e16a3"]} + [{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-nested-component {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n make-nested-component {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n paste-to-root {:target #fn, :new-head 5}\n test\n change-property {:target #fn, :property :fills, :value \"#ff0000\"}", :states ["c8c845596f55aa86" "0d2b7d7efc6e54d1" "8956d8fac4c6c4fb" "30c4e5a8979ec07f"]} {:transcript "create-component {:component \"main\", :id sync-main-component}\n make-nested-component {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n one-of -> skip\n paste-to-root {:target #fn, :new-head 3}\n test\n change-property {:target #fn, :property :fills, :value \"#ff0000\"}", :states ["c8c845596f55aa86" "a6a97a3d3298a63a" "a47933c7e373dfd7" "75123b44e98d2e2c"]}] :b [{:transcript "change-property {:target :copy-child, :property :fills, :value \"#00ff00\"}\n change-property {:target :main-child, :property :fills, :value \"#ff0000\"}", :states ["5df508d97af5247a" "b2f66a15e5ff4097" "4b24ab56135742f0"]}] diff --git a/frontend/test/frontend_tests/composable_tests/golden_master.edn b/frontend/test/frontend_tests/composable_tests/golden_master.edn index 2e5569efed..ddf59605bb 100644 --- a/frontend/test/frontend_tests/composable_tests/golden_master.edn +++ b/frontend/test/frontend_tests/composable_tests/golden_master.edn @@ -82,7 +82,7 @@ {:transcript " {:component \"main\", :id sync-main-component}\n {:tokens [[\"radius.s\" 10] [\"radius.l\" 30]]}\n {:component \"main\", :copy sync-main-copyhead-0}\n one-of -> \n {:target #fn, :token-name \"radius.l\", :value 30}\n \n {:target #fn, :token-name \"radius.l\"}", :states ["d0de1c63d1e2913a" "8e2ae96c4495f143" "608fefc00332c877"]} {:transcript " {:component \"main\", :id sync-main-component}\n {:tokens [[\"radius.s\" 10] [\"radius.l\" 30]]}\n {:component \"main\", :copy sync-main-copyhead-0}\n one-of -> \n {:target #fn, :token-name \"radius.l\", :value 30}\n \n one-of -> ", :states ["d0de1c63d1e2913a" "a3e49f56de0aaf82"]}] :case-az-copy-moved-out-of-its-main-keeps-inherited-overrides - [{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n {:target #fn, :new-head 5}\n \n {:target #fn, :property :fills, :value \"#ff0000\"}", :states ["d6802c2361c4f48a" "09526a373b2bf78d" "f6588d21ee3f82ea" "89696ef8abcbb71d"]} + [{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n {:target #fn, :new-head 5}\n \n {:target #fn, :property :fills, :value \"#ff0000\"}", :states ["d6802c2361c4f48a" "2ec99a7c1c3a764e" "63398e5920c78a16" "c26f774147ed5d8c"]} {:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n one-of -> \n {:target #fn, :new-head 3}\n \n {:target #fn, :property :fills, :value \"#ff0000\"}", :states ["d6802c2361c4f48a" "7443c8f4406f3704" "78edc4e41925495c" "62c32614a4d51244"]}] :case-b-copy-override-survives-later-main-change [{:transcript " {:target :copy-child, :property :fills, :value \"#00ff00\"}\n {:target :main-child, :property :fills, :value \"#ff0000\"}", :states ["83d0e402abf3aafe" "89465e6b1fc243c5" "009c37e0db2f75d7"]}]