0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 07:29:08 -05:00

🐛 Fix positioning on group and ungroup.

This commit is contained in:
Andrey Antukh 2020-06-12 11:58:49 +02:00 committed by Andrés Moya
parent 9ed6d23041
commit 861150ff46
2 changed files with 22 additions and 9 deletions

View file

@ -60,6 +60,13 @@
(or (not= (:type shape) :frame) (or (not= (:type shape) :frame)
(= parent-id uuid/zero)))) (= 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 (defn insert-at-index
[shapes index ids] [shapes index ids]
(let [[before after] (split-at index shapes) (let [[before after] (split-at index shapes)

View file

@ -1244,10 +1244,7 @@
group (-> (group-shape id frame-id selected selrect) group (-> (group-shape id frame-id selected selrect)
(geom/setup selrect)) (geom/setup selrect))
index (->> (get-in objects [frame-id :shapes]) index (cph/position-on-parent (:id (first items)) objects)
(map-indexed vector)
(filter #(selected (second %)))
(ffirst))
rchanges [{:type :add-obj rchanges [{:type :add-obj
:id id :id id
@ -1258,11 +1255,20 @@
{:type :mov-objects {:type :mov-objects
:parent-id id :parent-id id
:shapes (vec selected)}] :shapes (vec selected)}]
uchanges [{:type :mov-objects
:parent-id frame-id uchanges
:shapes (vec selected)} (reduce (fn [res obj]
{:type :del-obj (conj res {:type :mov-objects
:id id}]] :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}) (rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true})
(dws/select-shapes #{id})))))))) (dws/select-shapes #{id}))))))))