From 40195a4f520c73903051d52cda6c26464bcb805a Mon Sep 17 00:00:00 2001 From: Eva Date: Thu, 19 Jan 2023 14:35:20 +0100 Subject: [PATCH] :bug: Fix index on layout created over group --- common/src/app/common/pages/helpers.cljc | 10 ++++++++++ frontend/src/app/main/data/workspace/shape_layout.cljs | 5 +++-- frontend/src/app/main/data/workspace/shapes.cljs | 9 ++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/common/src/app/common/pages/helpers.cljc b/common/src/app/common/pages/helpers.cljc index bdc5a781f9..973c1a714b 100644 --- a/common/src/app/common/pages/helpers.cljc +++ b/common/src/app/common/pages/helpers.cljc @@ -353,6 +353,16 @@ (filter (comp (into #{} ids) second)) (map second))) +(defn get-index-replacement + "Given a collection of shapes, calculate their positions + in the parent, find first index and return next one" + [shapes objects] + (->> shapes + (order-by-indexed-shapes objects) + first + (get-position-on-parent objects) + inc)) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; SHAPES ORGANIZATION (PATH MANAGEMENT) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/frontend/src/app/main/data/workspace/shape_layout.cljs b/frontend/src/app/main/data/workspace/shape_layout.cljs index 85a429a538..fcf8f4dbf5 100644 --- a/frontend/src/app/main/data/workspace/shape_layout.cljs +++ b/frontend/src/app/main/data/workspace/shape_layout.cljs @@ -165,11 +165,12 @@ parent-id (:parent-id (first selected-shapes)) shapes-ids (:shapes (first selected-shapes)) ordered-ids (into (d/ordered-set) shapes-ids) - undo-id (js/Symbol)] + undo-id (js/Symbol) + group-index (cph/get-index-replacement selected objects)] (rx/of (dwu/start-undo-transaction undo-id) (dwse/select-shapes ordered-ids) - (dws/create-artboard-from-selection new-shape-id parent-id) + (dws/create-artboard-from-selection new-shape-id parent-id group-index) (cl/remove-all-fills [new-shape-id] {:color clr/black :opacity 1}) (create-layout-from-id [new-shape-id] type) diff --git a/frontend/src/app/main/data/workspace/shapes.cljs b/frontend/src/app/main/data/workspace/shapes.cljs index c6de6aa210..a8551942dd 100644 --- a/frontend/src/app/main/data/workspace/shapes.cljs +++ b/frontend/src/app/main/data/workspace/shapes.cljs @@ -359,6 +359,8 @@ ([id] (create-artboard-from-selection id nil)) ([id parent-id] + (create-artboard-from-selection id parent-id nil)) + ([id parent-id index] (ptk/reify ::create-artboard-from-selection ptk/WatchEvent (watch [_ state _] @@ -367,11 +369,8 @@ selected (wsh/lookup-selected state) selected (cph/clean-loops objects selected) selected-objs (map #(get objects %) selected) - new-index (->> selected - (cph/order-by-indexed-shapes objects) - first - (cph/get-position-on-parent objects) - inc)] + new-index (or index + (cph/get-index-replacement selected objects))] (when (d/not-empty? selected) (let [srect (gsh/selection-rect selected-objs) frame-id (get-in objects [(first selected) :frame-id])