From be656bb4efdd7af1a8e7a38742e290de430553d3 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Wed, 31 Aug 2022 18:37:35 +0200 Subject: [PATCH] :bug: Fix undo on delete page does not preserve its order --- CHANGES.md | 1 + common/src/app/common/types/pages_list.cljc | 19 ++++++++++++------- frontend/src/app/main/data/workspace.cljs | 5 ++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f0ac071694..2d0870900c 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 5275e480ea..3ff669b0c0 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 ae2795c36f..07fde93f50 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))]