diff --git a/common/uxbox/common/pages_helpers.cljc b/common/uxbox/common/pages_helpers.cljc index 1bcc63d3d..81e21cfd2 100644 --- a/common/uxbox/common/pages_helpers.cljc +++ b/common/uxbox/common/pages_helpers.cljc @@ -60,6 +60,13 @@ (or (not= (:type shape) :frame) (= parent-id uuid/zero)))) +(defn position-on-parent + [id objects] + (let [obj (get objects id) + pid (:parent-id obj) + prt (get objects pid)] + (d/index-of (:shapes prt) id))) + (defn insert-at-index [shapes index ids] (let [[before after] (split-at index shapes) diff --git a/frontend/src/uxbox/main/data/workspace.cljs b/frontend/src/uxbox/main/data/workspace.cljs index 8ad41e9de..c5dc1b901 100644 --- a/frontend/src/uxbox/main/data/workspace.cljs +++ b/frontend/src/uxbox/main/data/workspace.cljs @@ -1244,10 +1244,7 @@ group (-> (group-shape id frame-id selected selrect) (geom/setup selrect)) - index (->> (get-in objects [frame-id :shapes]) - (map-indexed vector) - (filter #(selected (second %))) - (ffirst)) + index (cph/position-on-parent (:id (first items)) objects) rchanges [{:type :add-obj :id id @@ -1258,11 +1255,20 @@ {:type :mov-objects :parent-id id :shapes (vec selected)}] - uchanges [{:type :mov-objects - :parent-id frame-id - :shapes (vec selected)} - {:type :del-obj - :id id}]] + + uchanges + (reduce (fn [res obj] + (conj res {:type :mov-objects + :parent-id (:parent-id obj) + :index (:index obj) + :shapes [(:id obj)]})) + [] + (->> selected + (map #(get objects %)) + (map #(assoc % :index (cph/position-on-parent (:id %) objects))) + (sort-by :index))) + + uchanges (conj uchanges {:type :del-obj :id id})] (rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true}) (dws/select-shapes #{id}))))))))