mirror of
https://github.com/penpot/penpot.git
synced 2025-05-29 08:06:15 +02:00
🐛 Fix corner case when selecting component to switch (#6350)
This commit is contained in:
parent
dfa6c502dc
commit
6fdaad1bf4
1 changed files with 9 additions and 5 deletions
|
@ -319,11 +319,15 @@
|
|||
(mf/use-fn
|
||||
(mf/deps shape)
|
||||
(fn [pos val]
|
||||
(let [valid-comps (->> variant-components
|
||||
(remove #(= (:id %) component-id))
|
||||
(filter #(= (dm/get-in % [:variant-properties pos :value]) val)))
|
||||
comp (apply min-key #(ctv/distance (:variant-properties component) (:variant-properties %)) valid-comps)]
|
||||
(st/emit! (dwl/component-swap shape (:component-file shape) (:id comp))))))]
|
||||
(when (not= val (dm/get-in component [:variant-properties pos :value]))
|
||||
(let [target-props (-> (:variant-properties component)
|
||||
(update pos assoc :value val))
|
||||
valid-comps (->> variant-components
|
||||
(remove #(= (:id %) component-id))
|
||||
(filter #(= (dm/get-in % [:variant-properties pos :value]) val)))
|
||||
nearest-comp (apply min-key #(ctv/distance target-props (:variant-properties %)) valid-comps)]
|
||||
(when nearest-comp
|
||||
(st/emit! (dwl/component-swap shape (:component-file shape) (:id nearest-comp))))))))]
|
||||
|
||||
[:*
|
||||
(for [[pos prop] (map vector (range) properties)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue