diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index d19bdfb37a..011e0fe809 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -1165,13 +1165,10 @@ (not= (get shape attr) (get reference attr))) group)))) updatable-attrs) - overrides (when text? (txt/text-overrides (:touched shape))) - ;; the copy's own styles drop a typography they do not all come with - dropped? (and (not (contains? overrides :text-content-typography)) - (some #(contains? overrides %) txt/typography-units)) text-groups (when text? (cond-> (txt/override-groups (:content reference) (:content shape)) - dropped? (disj :text-content-typography))) + (txt/drops-typography? (txt/text-overrides (:touched shape))) + (disj :text-content-typography))) groups (cond-> (into groups text-groups) (seq text-groups) (conj :content-group))] (cond-> shape diff --git a/common/src/app/common/logic/swap.cljc b/common/src/app/common/logic/swap.cljc index c780360611..d236b762ab 100644 --- a/common/src/app/common/logic/swap.cljc +++ b/common/src/app/common/logic/swap.cljc @@ -326,7 +326,10 @@ updated-attrs) new-content (some #(when (= (:attr %) :content) (:val %)) roperations) text-groups (when (and (cfh/text-shape? current-shape) (some? new-content)) - (txt/override-groups (:content current-shape) 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))) new-touched (set/union (or (:touched current-shape) #{}) updated-sync-groups text-groups diff --git a/common/src/app/common/types/text.cljc b/common/src/app/common/types/text.cljc index a05c836fa8..a7b42372bf 100644 --- a/common/src/app/common/types/text.cljc +++ b/common/src/app/common/types/text.cljc @@ -761,6 +761,14 @@ #{:text-content-family :text-content-weight :text-content-size :text-content-line-height :text-content-spacing :text-content-case}) +(defn drops-typography? + "Whether a copy text whose text overrides are `overrides` drops the + typography of its main: it overrides a unit the typography sets, but not + the typography." + [overrides] + (and (not (contains? overrides :text-content-typography)) + (boolean (some #(contains? overrides %) typography-units)))) + (defn typography-owner? "Whether `content` applies a typography, which owns every unit it sets." [content] diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index cf88501403..7616c042db 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1828,6 +1828,12 @@ :ops [[:nest 0 0 0 0] [:rotate 0 0 0 0] [:make-variant 0 0 0 0] [:swap 0 0 0 0] [:duplicate 0 0 0 0] [:text-style 0 0 1] [:update-main 0 0 0 0]]})))) +(t/deftest switching-a-resized-copy-text-to-a-typography-variant-holds-no-typography + (t/is (map? (cg/run {:world [2 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 [[:text 4 1 1 0] [:text-style 0 8 1] [:switch 1 0 0 0] [:switch 0 0 0 0]]})))) + (t/deftest random-variant-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 35e84a4475..5950077914 100644 --- a/common/test/common_tests/logic/text_override_switch_test.cljc +++ b/common/test/common_tests/logic/text_override_switch_test.cljc @@ -130,3 +130,22 @@ :text-content-weight :text-content-size :text-content-line-height :text-content-spacing :text-content-case} (:touched copy-t))))) + +(t/deftest copy-that-resizes-its-text-holds-no-typography-of-the-new-variant + ;; both variants show the same size, so the copy's own size stays and + ;; drops the typography the new variant applies, which then is no override + (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}) + (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)))))