From 3dd237002b94eee796198e0b65242303c82b9cb6 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Wed, 27 Aug 2025 13:00:28 +0200 Subject: [PATCH] :bug: Fix combine as variants from assets tab selects wrong components (#7190) --- common/src/app/common/files/helpers.cljc | 7 ++ .../src/app/main/data/workspace/variants.cljs | 95 +++++++++---------- .../workspace/sidebar/assets/components.cljs | 6 +- 3 files changed, 57 insertions(+), 51 deletions(-) diff --git a/common/src/app/common/files/helpers.cljc b/common/src/app/common/files/helpers.cljc index 4a12b22f64..afb0c4f4af 100644 --- a/common/src/app/common/files/helpers.cljc +++ b/common/src/app/common/files/helpers.cljc @@ -821,6 +821,13 @@ (let [path-split (split-path path)] (merge-path-item (first path-split) name))) +(defn inside-path? [child parent] + (let [child-path (split-path child) + parent-path (split-path parent)] + (and (<= (count parent-path) (count child-path)) + (= parent-path (take (count parent-path) child-path))))) + + (defn split-by-last-period "Splits a string into two parts: diff --git a/frontend/src/app/main/data/workspace/variants.cljs b/frontend/src/app/main/data/workspace/variants.cljs index 5ade4c3cca..811f3b4006 100644 --- a/frontend/src/app/main/data/workspace/variants.cljs +++ b/frontend/src/app/main/data/workspace/variants.cljs @@ -569,57 +569,56 @@ combine (fn [current-page] (let [objects (dsh/lookup-page-objects state current-page) - selected (or selected - (->> (dsh/lookup-selected state) - (cfh/clean-loops objects) - (remove (fn [id] - (let [shape (get objects id)] - (or (not (ctc/main-instance? shape)) - (ctc/is-variant? shape))))))) - shapes (mapv #(get objects %) selected) - rect (bounding-rect shapes) - prefix (->> shapes - (mapv #(cfh/split-path (:name %))) - (common-prefix)) - ;; When the common parent is root, add a wrapper - add-wrapper? (= prefix []) - first-shape (first shapes) - delta (gpt/point (- (:x rect) (:x first-shape) 30) - (- (:y rect) (:y first-shape) 30)) - common-parent (->> selected - (mapv #(-> (cfh/get-parent-ids objects %) reverse)) - common-prefix - last) - index (-> (get objects common-parent) - :shapes - count - inc) - variant-id (uuid/next) - undo-id (js/Symbol)] + selected (->> (or selected (dsh/lookup-selected state)) + (cfh/clean-loops objects) + (remove (fn [id] + (let [shape (get objects id)] + (or (not (ctc/main-instance? shape)) + (ctc/is-variant? shape))))))] + (when (> (count selected) 1) + (let [shapes (mapv #(get objects %) selected) + rect (bounding-rect shapes) + prefix (->> shapes + (mapv #(cfh/split-path (:name %))) + (common-prefix)) + ;; When the common parent is root, add a wrapper + add-wrapper? (empty? prefix) + first-shape (first shapes) + delta (gpt/point (- (:x rect) (:x first-shape) 30) + (- (:y rect) (:y first-shape) 30)) + common-parent (->> selected + (mapv #(-> (cfh/get-parent-ids objects %) reverse)) + common-prefix + last) + index (-> (get objects common-parent) + :shapes + count + inc) + variant-id (uuid/next) + undo-id (js/Symbol)] - (rx/concat - (if (and page-id (not= current-page page-id)) - (rx/of (dcm/go-to-workspace :page-id page-id)) - (rx/empty)) + (rx/concat + (if (and page-id (not= current-page page-id)) + (rx/of (dcm/go-to-workspace :page-id page-id)) + (rx/empty)) - (rx/of (dwu/start-undo-transaction undo-id) - (transform-in-variant (first selected) variant-id delta prefix add-wrapper? false false) - (dwsh/relocate-shapes (into #{} (-> selected rest reverse)) variant-id 0) - (dwsh/update-shapes selected #(-> % - (assoc :constraints-h :left) - (assoc :constraints-v :top) - (assoc :fixed-scroll false))) - (dwsh/relocate-shapes #{variant-id} common-parent index) - (dwt/update-dimensions [variant-id] :width (+ (:width rect) 60)) - (dwt/update-dimensions [variant-id] :height (+ (:height rect) 60))) + (rx/of (dwu/start-undo-transaction undo-id) + (transform-in-variant (first selected) variant-id delta prefix add-wrapper? false false) + (dwsh/relocate-shapes (into #{} (-> selected rest reverse)) variant-id 0) + (dwsh/update-shapes selected #(-> % + (assoc :constraints-h :left) + (assoc :constraints-v :top) + (assoc :fixed-scroll false))) + (dwsh/relocate-shapes #{variant-id} common-parent index) + (dwt/update-dimensions [variant-id] :width (+ (:width rect) 60)) + (dwt/update-dimensions [variant-id] :height (+ (:height rect) 60))) - ;; NOTE: we need to schedule a commit into a - ;; microtask for ensure that all the scheduled - ;; microtask of previous events execute before the - ;; commit - - (->> (rx/of (dwu/commit-undo-transaction undo-id)) - (rx/observe-on :async))))) + ;; NOTE: we need to schedule a commit into a + ;; microtask for ensure that all the scheduled + ;; microtask of previous events execute before the + ;; commit + (->> (rx/of (dwu/commit-undo-transaction undo-id)) + (rx/observe-on :async))))))) redirect-to-page (fn [page-id] diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets/components.cljs b/frontend/src/app/main/ui/workspace/sidebar/assets/components.cljs index 42cefd25a9..d368e46e33 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets/components.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/assets/components.cljs @@ -460,7 +460,7 @@ (st/emit! (dwu/start-undo-transaction undo-id)) (run! st/emit! (->> components - (filter #(str/starts-with? (:path %) path)) + (filter #(cfh/inside-path? (:path %) path)) (map #(dwv/rename-comp-or-variant-and-main (:id %) (cmm/rename-group % path last-path))))) @@ -491,7 +491,7 @@ (st/emit! (dwu/start-undo-transaction undo-id)) (run! st/emit! (->> components - (filter #(str/starts-with? (:path %) path)) + (filter #(cfh/inside-path? (:path %) path)) (map #(dwv/rename-comp-or-variant-and-main (:id %) (cmm/ungroup % path))))) (st/emit! (dwu/commit-undo-transaction undo-id))))) @@ -501,7 +501,7 @@ (fn [path] (on-clear-selection) (let [comps (->> components - (filter #(str/starts-with? (:path %) path))) + (filter #(cfh/inside-path? (:path %) path))) ids (into #{} (map :main-instance-id comps)) page-id (->> comps first :main-instance-page)]