From c1778338e4b688513168585313c8aa0b66320bbc Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 13 Nov 2026 01:09:05 +0100 Subject: [PATCH] :bug: Take off the token of the corner a flipped shape shows A border radius token names the corners as a flipped shape shows them: applying and propagating it mirror each corner to the one the shape stores. A radius edit took off the token of the corner it stores, so on a flipped shape it took off the wrong one, and a later token edit set the corner given by hand. The sidebar's single-corner edit mirrored the corner too but wrote only the corner it names, so on a flipped rectangle it changed nothing. A radius edit takes off the token of the corner the shape shows, with the same mirroring, and the sidebar's single-corner edit writes any corner. The harness model does the same. Tests: unapply-the-token-of-the-corner-a-flipped-shape-shows; a-token-edit-sets-the-corners-of-a-flipped-copy-as-it-shows-them. The benchmark of the previous commit covers this one. AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/shapes.cljc | 4 ++++ .../common/test_helpers/composable/shadow.cljc | 6 ++++-- common/src/app/common/types/shape/radius.cljc | 18 ++++++++++++------ .../common_tests/logic/token_apply_test.cljc | 15 +++++++++++++++ .../sidebar/options/menus/border_radius.cljs | 5 +++-- 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/common/src/app/common/logic/shapes.cljc b/common/src/app/common/logic/shapes.cljc index 4bf8ff9853..edd7463d8d 100644 --- a/common/src/app/common/logic/shapes.cljc +++ b/common/src/app/common/logic/shapes.cljc @@ -20,6 +20,7 @@ [app.common.types.pages-list :as ctpl] [app.common.types.shape.interactions :as ctsi] [app.common.types.shape.layout :as ctl] + [app.common.types.shape.radius :as ctsr] [app.common.types.shape.token :as ctst] [app.common.types.text :as ctt] [app.common.types.token :as cto] @@ -64,6 +65,9 @@ (not (zero? changed-item-index)) (= (first (get shape attr)) (first (get (get new-objects shape-id) attr))))) + ;; a radius token names a corner as the shape shows it + attr (cond->> attr + (contains? #{:r1 :r2 :r3 :r4} attr) (ctsr/shown-corner shape)) token-attrs (when-not later-item? (if (and (cfh/text-shape? shape) (= attr :content)) (text-changed-attrs shape) diff --git a/common/src/app/common/test_helpers/composable/shadow.cljc b/common/src/app/common/test_helpers/composable/shadow.cljc index 945c2221ff..87a12519a5 100644 --- a/common/src/app/common/test_helpers/composable/shadow.cljc +++ b/common/src/app/common/test_helpers/composable/shadow.cljc @@ -272,8 +272,10 @@ (defn edit [model before property value] (let [after (cond-> (n/set-property before property value) - ;; a radius set by hand takes off the token its corner applied - (contains? n/radius-attrs property) (update :applied-tokens dissoc property)) + ;; a radius set by hand takes off the token of its corner, which a + ;; token names as the shape shows it + (contains? n/radius-attrs property) + (update :applied-tokens dissoc (ctsr/shown-corner before property))) group (get groups property)] (if (and (:shape-ref before) (not= (get before property) (get after property))) (assoc-in model [(:id before) group] (values after group)) diff --git a/common/src/app/common/types/shape/radius.cljc b/common/src/app/common/types/shape/radius.cljc index 46dfa2dacb..fd7d492d23 100644 --- a/common/src/app/common/types/shape/radius.cljc +++ b/common/src/app/common/types/shape/radius.cljc @@ -44,14 +44,20 @@ (can-get-border-radius? shape) (assoc :r1 value :r2 value :r3 value :r4 value))) +(defn shown-corner + "The corner `attr` of `shape` as the shape shows it, mirrored by its flips; + the same mirroring takes a shown corner to the one it stores." + [shape attr] + (cond->> attr + (:flip-x shape) + (get {:r1 :r2 :r2 :r1 :r3 :r4 :r4 :r3}) + + (:flip-y shape) + (get {:r1 :r4 :r2 :r3 :r3 :r2 :r4 :r1}))) + (defn set-radius-to-single-corner [shape attr value] - (let [attr (cond->> attr - (:flip-x shape) - (get {:r1 :r2 :r2 :r1 :r3 :r4 :r4 :r3}) - - (:flip-y shape) - (get {:r1 :r4 :r2 :r3 :r3 :r2 :r4 :r1}))] + (let [attr (shown-corner shape attr)] ;; Only Apply changes to shapes that support border Radius (cond-> shape (can-get-border-radius? shape) diff --git a/common/test/common_tests/logic/token_apply_test.cljc b/common/test/common_tests/logic/token_apply_test.cljc index 544af2ff9d..dce46d9dca 100644 --- a/common/test/common_tests/logic/token_apply_test.cljc +++ b/common/test/common_tests/logic/token_apply_test.cljc @@ -364,6 +364,21 @@ (t/is (= (count applied-tokens-text') 0)) (t/is (= (count applied-tokens-circle') 0)))) +(t/deftest unapply-the-token-of-the-corner-a-flipped-shape-shows + (let [file (-> (thf/sample-file :file1) + (ths/add-sample-shape :rect :type :rect :flip-x true + :applied-tokens {:r1 "radius.s"})) + page (thf/current-page file) + rect (ths/get-shape file :rect) + ;; the stored corner a flipped shape shows as its first one + changes (-> (pcb/empty-changes nil) + (pcb/with-page page) + (pcb/with-objects (:objects page)) + (cls/generate-update-shapes [(:id rect)] #(assoc % :r2 8) (:objects page) {})) + rect' (ths/get-shape (thf/apply-changes file changes) :rect)] + (t/is (= 8 (:r2 rect'))) + (t/is (empty? (:applied-tokens rect'))))) + (t/deftest unapply-only-changed-per-side-token (let [file (-> (setup-file) (tht/apply-token-to-shape :frame1 "token-stroke-width" diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/border_radius.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/border_radius.cljs index 5f3aef23a3..2b4e21c73e 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/border_radius.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/border_radius.cljs @@ -108,17 +108,18 @@ {:reg-objects? true :attrs [:r1 :r2 :r3 :r4]}))) + ;; a flipped shape stores the corner it shows under another name change-one-radius (mf/use-fn (mf/deps ids) - (fn [update-fn attr] + (fn [update-fn _attr] (dwsh/update-shapes ids (fn [shape] (if (ctsr/has-radius? shape) (update-fn shape) shape)) {:reg-objects? true - :attrs [attr]}))) + :attrs [:r1 :r2 :r3 :r4]}))) toggle-radius-mode (mf/use-fn