mirror of
https://github.com/penpot/penpot.git
synced 2025-06-01 04:41:40 +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/use-fn
|
||||||
(mf/deps shape)
|
(mf/deps shape)
|
||||||
(fn [pos val]
|
(fn [pos val]
|
||||||
(let [valid-comps (->> variant-components
|
(when (not= val (dm/get-in component [:variant-properties pos :value]))
|
||||||
(remove #(= (:id %) component-id))
|
(let [target-props (-> (:variant-properties component)
|
||||||
(filter #(= (dm/get-in % [:variant-properties pos :value]) val)))
|
(update pos assoc :value val))
|
||||||
comp (apply min-key #(ctv/distance (:variant-properties component) (:variant-properties %)) valid-comps)]
|
valid-comps (->> variant-components
|
||||||
(st/emit! (dwl/component-swap shape (:component-file shape) (:id comp))))))]
|
(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)]
|
(for [[pos prop] (map vector (range) properties)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue