diff --git a/CHANGES.md b/CHANGES.md index f0ac07169..2d0870900 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,6 +22,7 @@ - Fix props preserving on copy&paste texts [Taiga #3629](https://tree.taiga.io/project/penpot/issue/3629) by @andrewzhurov - Fix unexpected layers ungrouping on moving it [Taiga #3932](https://tree.taiga.io/project/penpot/issue/3932) by @andrewzhurov - Fix artboards moving with comment tool selected [Taiga #3938](https://tree.taiga.io/project/penpot/issue/3938) +- Fix undo on delete page does not preserve its order [Taiga #3375](https://tree.taiga.io/project/penpot/issue/3375) ### :arrow_up: Deps updates ### :heart: Community contributions by (Thank you!) diff --git a/common/src/app/common/types/pages_list.cljc b/common/src/app/common/types/pages_list.cljc index 5275e480e..3ff669b0c 100644 --- a/common/src/app/common/types/pages_list.cljc +++ b/common/src/app/common/types/pages_list.cljc @@ -6,7 +6,8 @@ (ns app.common.types.pages-list (:require - [app.common.data :as d])) + [app.common.data :as d] + [app.common.pages.helpers :as cph])) (defn get-page [file-data id] @@ -14,14 +15,18 @@ (defn add-page [file-data page] - (let [; It's legitimate to add a page that is already there, + (let [index (:index page) + page (dissoc page :index) + + ; It's legitimate to add a page that is already there, ; for example in an idempotent changes operation. - conj-if-not-exists (fn [pages id] - (cond-> pages - (not (d/seek #(= % id) pages)) - (conj id)))] + add-if-not-exists (fn [pages id] + (cond + (d/seek #(= % id) pages) pages + (nil? index) (conj pages id) + :else (cph/insert-at-index pages index [id])))] (-> file-data - (update :pages conj-if-not-exists (:id page)) + (update :pages add-if-not-exists (:id page)) (update :pages-index assoc (:id page) page)))) (defn pages-seq diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index ae2795c36..07fde93f5 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -326,7 +326,10 @@ (ptk/reify ::delete-page ptk/WatchEvent (watch [it state _] - (let [page (get-in state [:workspace-data :pages-index id]) + (let [pages (get-in state [:workspace-data :pages]) + index (d/index-of pages id) + page (get-in state [:workspace-data :pages-index id]) + page (assoc page :index index) changes (-> (pcb/empty-changes it) (pcb/del-page page))]