diff --git a/CHANGES.md b/CHANGES.md index 6fb091af3..9288f3516 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,7 @@ - Fix problem with mask and flip [#715](https://github.com/penpot/penpot/issues/715) - Fix problem with rotated blur [Taiga #1370](https://tree.taiga.io/project/penpot/issue/1370) - Disables buttons in view mode for users without permissions [Taiga #1328](https://tree.taiga.io/project/penpot/issue/1328) +- Fix issue when undo after changing the artboard of a shape [Taiga #1304](https://tree.taiga.io/project/penpot/issue/1304) ### :heart: Community contributions by (Thank you!) diff --git a/common/app/common/pages.cljc b/common/app/common/pages.cljc index aa54c710a..1b82300f7 100644 --- a/common/app/common/pages.cljc +++ b/common/app/common/pages.cljc @@ -62,6 +62,7 @@ (d/export helpers/touched-group?) (d/export helpers/get-base-shape) (d/export helpers/is-parent?) +(d/export helpers/get-index-in-parent) ;; Process changes (d/export changes/process-changes) diff --git a/common/app/common/pages/helpers.cljc b/common/app/common/pages/helpers.cljc index e630801da..6dc4ccbf1 100644 --- a/common/app/common/pages/helpers.cljc +++ b/common/app/common/pages/helpers.cljc @@ -401,3 +401,12 @@ (recur (get objects (first pending)) (conj done (:id current)) (concat (rest pending) (:shapes current)))))) + +(defn get-index-in-parent + "Retrieves the index in the parent" + [objects shape-id] + (let [shape (get objects shape-id) + parent (get objects (:parent-id shape)) + [parent-idx _] (d/seek (fn [[idx child-id]] (= child-id shape-id)) + (d/enumerate (:shapes parent)))] + parent-idx)) diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index 57be6ef0b..636391406 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -249,14 +249,15 @@ :parent-id frame-id :shapes (mapv :id moving-shapes)}] - moving-shapes-by-frame-id (group-by :frame-id moving-shapes) - uch (->> moving-shapes-by-frame-id - (mapv (fn [[frame-id shapes]] + uch (->> moving-shapes + (reverse) + (mapv (fn [shape] {:type :mov-objects :page-id page-id - :parent-id frame-id - :shapes (mapv :id shapes)})))] + :parent-id (:parent-id shape) + :index (cp/get-index-in-parent objects (:id shape)) + :shapes [(:id shape)]})))] (when-not (empty? rch) (rx/of dwc/pop-undo-into-transaction