From 6fdaad1bf475db92b2f68126a7ee9f493dbfb1ed Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Thu, 24 Apr 2025 10:38:32 +0200 Subject: [PATCH] :bug: Fix corner case when selecting component to switch (#6350) --- .../workspace/sidebar/options/menus/component.cljs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs index df5e979fce..bfa26a0209 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs @@ -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)]