🐛 Switch no typography a copy text's own styles drop

A copy text that overrides its size, and switches to a variant whose
text applies a typography, keeps its size when both variants show the
same one; the typography, whose size is not the copy's, is dropped. The
switch then authored the missing reference as a typography override the
copy never made. txt/drops-typography? tells when a copy's text
overrides hold a unit a typography sets but not the typography; the
switch then leaves out the typography group, and the update-main push
uses the same helper.

Tests: copy-that-resizes-its-text-holds-no-typography-of-the-new-variant
and the regression program
switching-a-resized-copy-text-to-a-typography-variant-holds-no-typography.
Full common suite: 2351 tests, 0 failures.

Benchmark (scripts/bench-components, ms, lower 2.5% quantile):

|                             :world | :baseline |   :now |  :mean | :ratio |
|------------------------------------+-----------+--------+--------+--------|
|  deepest-edit-through-three-levels |    35.215 | 21.282 | 21.706 |    0.6 |
| edit-through-a-chain-of-dependents |    68.931 |  41.59 | 43.639 |    0.6 |
|         library-update-into-copies |    83.083 | 46.407 | 49.512 |   0.56 |
|        main-edit-among-many-shapes |     4.837 |  2.075 |  2.227 |   0.43 |
|           main-edit-into-10-copies |      1.79 |   0.96 |  1.042 |   0.54 |
|          main-edit-into-100-copies |    15.415 |  9.576 | 10.099 |   0.62 |
|         main-edit-into-1000-copies |   153.086 | 94.283 | 98.829 |   0.62 |
|         variant-switch-into-copies |    32.052 | 22.495 | 22.945 |    0.7 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-08 14:27:23 +01:00
parent a578321bf4
commit 16b196835f
5 changed files with 39 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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]

View File

@ -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)]

View File

@ -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)))))