🐛 Fix sync of margin and padding tokens in components

This commit is contained in:
Andrés Moya 2025-03-31 14:22:33 +02:00 committed by Andrés Moya
parent 89876ef96f
commit 2c0e18ce1c
2 changed files with 32 additions and 5 deletions

View file

@ -1639,7 +1639,21 @@
(if (and (empty? roperations) (empty? applied-tokens)) (if (and (empty? roperations) (empty? applied-tokens))
changes changes
(let [all-parents (cfh/get-parent-ids (:objects container) (let [all-parents (cfh/get-parent-ids (:objects container)
(:id dest-shape))] (:id dest-shape))
;; Sync tokens of attributes ignored above.
;; FIXME: this probably may be merged with the other calculation
;; of applied tokens, below, and to the calculation only once
;; for all sync-attrs.
applied-tokens (reduce (fn [applied-tokens attr]
(let [attr-group (get ctk/sync-attrs attr)
token-attrs (cto/shape-attr->token-attrs attr)]
(if (not (and (touched attr-group)
omit-touched?))
(into applied-tokens token-attrs)
applied-tokens)))
applied-tokens
ctk/swap-keep-attrs)]
(cond-> changes (cond-> changes
(seq roperations) (seq roperations)
(-> (update :redo-changes conj (make-change (-> (update :redo-changes conj (make-change

View file

@ -182,14 +182,27 @@
([shape-attr] (shape-attr->token-attrs shape-attr nil)) ([shape-attr] (shape-attr->token-attrs shape-attr nil))
([shape-attr changed-sub-attr] ([shape-attr changed-sub-attr]
(cond (cond
(= :fills shape-attr) #{:fill} (= :fills shape-attr)
(and (= :strokes shape-attr) (nil? changed-sub-attr)) #{:stroke-width :stroke-color} #{:fill}
(and (= :strokes shape-attr) (nil? changed-sub-attr))
#{:stroke-width :stroke-color}
(= :strokes shape-attr) (= :strokes shape-attr)
(cond (cond
(some #{:stroke-color} changed-sub-attr) #{:stroke-color} (some #{:stroke-color} changed-sub-attr) #{:stroke-color}
(some #{:stroke-width} changed-sub-attr) #{:stroke-width}) (some #{:stroke-width} changed-sub-attr) #{:stroke-width})
(and (= :layout-padding shape-attr) (seq changed-sub-attr)) changed-sub-attr
(and (= :layout-item-margin shape-attr) (seq changed-sub-attr)) changed-sub-attr (= :layout-padding shape-attr)
(if (seq changed-sub-attr)
changed-sub-attr
#{:p1 :p2 :p3 :p4})
(= :layout-item-margin shape-attr)
(if (seq changed-sub-attr)
changed-sub-attr
#{:m1 :m2 :m3 :m4})
(border-radius-keys shape-attr) #{shape-attr} (border-radius-keys shape-attr) #{shape-attr}
(sizing-keys shape-attr) #{shape-attr} (sizing-keys shape-attr) #{shape-attr}
(opacity-keys shape-attr) #{shape-attr} (opacity-keys shape-attr) #{shape-attr}