0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-27 23:21:47 -05:00

🐛 Fix group undo/redo.

This commit is contained in:
Andrey Antukh 2020-04-15 09:24:29 +02:00
parent 527acac92e
commit 5fb0c5c312
3 changed files with 33 additions and 22 deletions

View file

@ -139,7 +139,7 @@
(defmethod change-spec-impl :add-obj [_]
(s/keys :req-un [::id ::frame-id ::obj]
:opt-un [::session-id]))
:opt-un [::session-id ::parent-id]))
(defmethod change-spec-impl :mod-obj [_]
(s/keys :req-un [::id ::operations]
@ -247,7 +247,7 @@
(contains? (:objects data) frame-id)
(update-in [:objects frame-id :shapes] (fn [s] (filterv #(not= % id) s)))
(seq shapes) ; Recursive delete all dependend objects
(seq shapes) ; Recursive delete all dependend objects
(as-> $ (reduce #(or (process-change %1 {:type :del-obj :id %2}) %1) $ shapes))))))
(defn- calculate-child-parent-map

View file

@ -7,16 +7,15 @@
;;
;; Copyright (c) 2020 UXBOX Labs SL
(ns uxbox.main.data.helpers)
(ns uxbox.main.data.helpers
(:require [uxbox.common.data :as d]))
(defn get-children
"Retrieve all children ids recursively for a given shape"
[shape-id objects]
(let [shapes (get-in objects [shape-id :shapes])]
(if shapes
(concat
shapes
(mapcat #(get-children % objects) shapes))
(d/concat shapes (mapcat #(get-children % objects) shapes))
[])))
(defn is-shape-grouped
@ -25,11 +24,11 @@
(let [contains-shape-fn
(fn [{:keys [shapes]}] ((set shapes) shape-id))
shapes (remove #(= (:type %) :frame) (vals objects))]
shapes (remove #(= (:type %) :frame) (vals objects))]
(some contains-shape-fn shapes)))
(defn get-parent
"Retrieve the id of the parent for the shape-id (if exists"
"Retrieve the id of the parent for the shape-id (if exists)"
[shape-id objects]
(let [check-parenthood
(fn [shape] (when (and (:shapes shape)
@ -55,9 +54,10 @@
(rec-fn shape-id [])))
(defn replace-shapes
"Replace inside shapes the value `to-replace-id` for the value in items keeping the same order.
`to-replace-id` can be a set, a sequable or a single value. Any of these will be changed into a
set to make the replacement"
"Replace inside shapes the value `to-replace-id` for the value in
items keeping the same order. `to-replace-id` can be a set, a
sequable or a single value. Any of these will be changed into a set
to make the replacement"
[shape to-replace-id items]
(let [should-replace
(cond

View file

@ -1318,17 +1318,28 @@
(let [page-id (::page-id state)
session-id (:session-id state)
objects (get-in state [:workspace-data page-id :objects])
rchanges (mapv #(array-map :type :del-obj :id %) ids)
uchanges (mapv (fn [id]
(let [obj (get objects id)
frm (get objects (:frame-id obj))
idx (d/index-of (:shapes frm) id)]
{:type :add-obj
:id id
:frame-id (:id frm)
:index idx
:obj obj}))
(reverse ids))]
cpindex (helpers/calculate-child-parent-map objects)
del-change #(array-map :type :del-obj :id %)
rchanges
(reduce (fn [res id]
(let [chd (helpers/get-children id objects)]
(into res (d/concat
(mapv del-change (reverse chd))
[(del-change id)]))))
[]
ids)
uchanges
(mapv (fn [id]
(let [obj (get objects id)]
{:type :add-obj
:id id
:frame-id (:frame-id obj)
:parent-id (get cpindex id)
:obj obj}))
(reverse (map :id rchanges)))]
(rx/of (commit-changes rchanges uchanges {:commit-local? true}))))))
(defn- delete-frame