🐛 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
This commit is contained in:
alonso.torres 2026-11-13 01:09:05 +01:00
parent f6d4e5dcd5
commit c1778338e4
5 changed files with 38 additions and 10 deletions

View File

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

View File

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

View File

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

View File

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

View File

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