From c13dcdd71fa57717ad6a12b2828961778ae31694 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 2 Nov 2026 22:02:53 +0100 Subject: [PATCH] :bug: Keep a copy text's own variant when both sides show its weight A copy text that sets its own family and weight keeps the variant id its family names for that weight. When the main later shows the same weight, the weight is equal on both sides and sync does not place it, so the family's variant ids were not given either: the copy's Roboto run took the main's "bold", a variant of another family. The family's side now gives its variants whenever the family is placed and the weight is not. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 20.095 | 0.57 | | edit-through-a-chain-of-dependents | 68.931 | 39.445 | 0.57 | | library-update-into-copies | 83.083 | 45.617 | 0.55 | | main-edit-among-many-shapes | 4.837 | 2.227 | 0.46 | | main-edit-into-10-copies | 1.79 | 0.961 | 0.54 | | main-edit-into-100-copies | 15.415 | 9.374 | 0.61 | | main-edit-into-1000-copies | 153.086 | 94.792 | 0.62 | | variant-switch-into-copies | 32.052 | 20.436 | 0.64 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/types/text.cljc | 5 +++-- common/test/common_tests/logic/composable_gen_test.cljc | 8 ++++++++ .../test/common_tests/logic/text_override_sync_test.cljc | 8 ++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/types/text.cljc b/common/src/app/common/types/text.cljc index bb6749417c..b96afa80f3 100644 --- a/common/src/app/common/types/text.cljc +++ b/common/src/app/common/types/text.cljc @@ -1047,9 +1047,10 @@ units)] (if (and (empty? placed) (not drop-typo?)) base - ;; the family's side names the variants of its family + ;; the family's side names the variants of its family, also when + ;; both sides show the same weight and it is not placed (let [variants (when (and (contains? placed :text-content-family) - (not-any? #{:text-content-weight} units)) + (not (contains? placed :text-content-weight))) (place-unit src dst @lmap :text-content-weight (unit-values src :text-content-weight) false))] (letters->content (write-units dst placed drop-typo? variants)))))))) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index d5a72a0063..13441cae57 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -996,3 +996,11 @@ :layout-copies true :text true}] :ops [[:grid-direction 0 0 0 1] [:grid-cell 0 0 0 1] [:grid-direction 0 0 15 0] [:edit 3 0 1 1] [:update-main 3] [:style 1 11 0 0]]})))) + +(t/deftest generated-copy-text-with-its-own-family-and-weight-keeps-its-variant + ;; a copy text sets its own family and the weight its main then takes too; + ;; a later sync keeps the variant its own family names for that weight + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :rich-variants true + :layout-copies true :text true}] + :ops [[:nest 0 0 0 0] [:text-style 0 1 1] [:duplicate 0 0 0 0] + [:update-main 1 0 0 0] [:text-style 0 0 1]]})))) diff --git a/common/test/common_tests/logic/text_override_sync_test.cljc b/common/test/common_tests/logic/text_override_sync_test.cljc index 640f8a6806..4de6aebc0a 100644 --- a/common/test/common_tests/logic/text_override_sync_test.cljc +++ b/common/test/common_tests/logic/text_override_sync_test.cljc @@ -183,6 +183,14 @@ [[["Hello world" {:family "Roboto" :weight 700}]]] [[["Hello world" {:weight 700 :color :blue}]]])))) +(t/deftest copy-with-its-own-family-and-weight-keeps-its-familys-variant + ;; the copy's Roboto names its bold "700"; the main turning bold as well + ;; leaves the weight equal on both sides, and the main's "bold" stays its own + (t/is (= [[["Hello world" {:family "Roboto" :weight 700 :color :blue}]]] + (sync-text [[["Hello world"]]] + [[["Hello world" {:family "Roboto" :weight 700}]]] + [[["Hello world" {:weight 700 :color :blue}]]])))) + (t/deftest copy-that-bolds-a-word-the-main-replaces-loses-the-bold ;; "Goodbye" shares no stretch of 3 letters with "Hello", so it takes the ;; style of the first shared letter after it, the regular space