diff --git a/common/src/app/common/logic/swap.cljc b/common/src/app/common/logic/swap.cljc index 01a758f133..e1ca9731ad 100644 --- a/common/src/app/common/logic/swap.cljc +++ b/common/src/app/common/logic/swap.cljc @@ -329,10 +329,14 @@ updated-attrs) new-content (some #(when (= (:attr %) :content) (:val %)) roperations) text-groups (when (and (cfh/text-shape? current-shape) (some? new-content)) - (cond-> (txt/override-groups (:content current-shape) new-content) - ;; the copy's own styles drop a typography it does not apply - (txt/drops-typography? (txt/text-overrides touched)) - (disj :text-content-typography))) + (let [;; the text overrides the switch carries: those both variants agree on + carried (set/difference (txt/text-overrides touched) + (txt/override-groups (:content origin-ref-shape) + (:content current-shape)))] + (cond-> (txt/override-groups (:content current-shape) new-content) + ;; the copy's own styles drop a typography it does not apply + (txt/drops-typography? carried) + (disj :text-content-typography)))) new-touched (set/union (or (:touched current-shape) #{}) updated-sync-groups text-groups diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index ed4687d6f9..ab4b12f498 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1906,6 +1906,18 @@ [:library-text-style 0 8 1] [:delete 0 0 0 0] [:library-edit 0 0 0] [:edit 0 1 1 2] [:library-sync] [:text-style 14 8 0 0]]})))) +(t/deftest switching-a-copy-text-marked-with-an-unapplied-typography-holds-none + (t/is (map? (cg/run {:world [2 1 {:variants true :text-styles true :library-variants true + :stale-libraries true :layout nil :layout-item-margins false + :grid-square false :library-depth 1 :library true + :rich-variants true :layout-children false :library-text true + :grid-empty false :layout-copies true :text true}] + :ops [[:library-add-variant 0] [:library-sync] [:switch 3] [:library-text-style 11 8 1] + [:library-make-variant 20 0 0 0] [:nest 0 0 0 0] [:library-make-variant 0] + [:library-sync] [:switch 0] [:nest 12 0 0 0] [:text 12 15 1] [:nest 4 0 0 0] + [:library-text-style 19 0 1] [:library-delete 0 0 0 0] + [:library-variant-property 0 0 0 0] [:library-sync] [:switch 19]]})))) + (t/deftest random-library-compositions (let [coverage (atom {}) failure (atom nil)] diff --git a/common/test/common_tests/logic/text_override_switch_test.cljc b/common/test/common_tests/logic/text_override_switch_test.cljc index 5950077914..1598a5891b 100644 --- a/common/test/common_tests/logic/text_override_switch_test.cljc +++ b/common/test/common_tests/logic/text_override_switch_test.cljc @@ -149,3 +149,24 @@ copy-t (ths/get-shape-by-id file (first (:shapes (ths/get-shape file :copy-2))))] (t/is (not-any? :typography-ref-id (tree-seq map? :children (:content copy-t)))) (t/is (= #{:content-group :text-content-size} (:touched copy-t))))) + +(t/deftest copy-owning-no-typography-holds-none-of-the-new-variant + ;; the copy is marked as owning its typography, though neither it nor its + ;; main applies one; the variants disagree on the typography, so only the + ;; size carries and drops the typography the new variant applies + (let [large [[["Add to cart" {:size 24}]]] + heading (thtx/apply-typography small :heading {:size 24 :weight 700}) + file (-> (thf/sample-file :file1) + (ths/add-sample-typography :heading) + (thv/add-variant-with-text :v01 :c01 :m01 :c02 :m02 :t01 :t02 "" "" + :text1-params {:content (thtx/content large)} + :text2-params {:content (thtx/content heading)}) + (thc/instantiate-component :c01 :copy :children-labels [:copy-t]) + (thtx/set-text :copy-t (thtx/restyle large :size 18)) + (ths/update-shape :copy-t :touched #{:content-group :text-content-size + :text-content-typography}) + (tho/swap-component-in-shape :copy :c02 {:new-shape-label :copy-2 + :keep-touched? true})) + copy-t (ths/get-shape-by-id file (first (:shapes (ths/get-shape file :copy-2))))] + (t/is (not-any? :typography-ref-id (tree-seq map? :children (:content copy-t)))) + (t/is (= #{:content-group :text-content-size} (:touched copy-t)))))