From 7efc1a0366cd26622d849468b90828a252959332 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 15 Jul 2021 13:20:12 +0200 Subject: [PATCH] :bug: Fix problem with undo operation and children order --- common/src/app/common/pages/helpers.cljc | 3 ++- frontend/src/app/main/data/workspace/common.cljs | 12 ++++++++---- frontend/src/app/main/data/workspace/undo.cljs | 5 ++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/common/src/app/common/pages/helpers.cljc b/common/src/app/common/pages/helpers.cljc index 2c7507243e..37d7febeea 100644 --- a/common/src/app/common/pages/helpers.cljc +++ b/common/src/app/common/pages/helpers.cljc @@ -99,7 +99,8 @@ ;; Implemented with transient for performance (defn get-children - "Retrieve all children ids recursively for a given object" + "Retrieve all children ids recursively for a given object. The + children's order will be breadth first." [id objects] (loop [result (transient []) diff --git a/frontend/src/app/main/data/workspace/common.cljs b/frontend/src/app/main/data/workspace/common.cljs index 75e9ce724e..5d6d7c00f3 100644 --- a/frontend/src/app/main/data/workspace/common.cljs +++ b/frontend/src/app/main/data/workspace/common.cljs @@ -350,6 +350,8 @@ (let [page-id (:current-page-id state) objects (wsh/lookup-page-objects state page-id) + ids (cp/clean-loops objects ids) + groups-to-unmask (reduce (fn [group-ids id] ;; When the shape to delete is the mask of a masked group, @@ -387,10 +389,12 @@ ids) all-children - (reduce (fn [res id] - (into res (cp/get-children id objects))) - (d/ordered-set) - ids) + (->> ids + (reduce (fn [res id] + (into res (cp/get-children id objects))) + []) + (reverse) + (into (d/ordered-set))) empty-parents (into (d/ordered-set) empty-parents-xform all-parents) diff --git a/frontend/src/app/main/data/workspace/undo.cljs b/frontend/src/app/main/data/workspace/undo.cljs index 85651e0d88..dd2ded3ce6 100644 --- a/frontend/src/app/main/data/workspace/undo.cljs +++ b/frontend/src/app/main/data/workspace/undo.cljs @@ -6,7 +6,6 @@ (ns app.main.data.workspace.undo (:require - [app.common.pages :as cp] [app.common.pages.spec :as spec] [app.common.spec :as us] [cljs.spec.alpha :as s] @@ -31,13 +30,13 @@ (subvec undo (- cnt MAX-UNDO-SIZE)) undo))) +;; TODO: Review the necessity of this method (defn materialize-undo - [changes index] + [_changes index] (ptk/reify ::materialize-undo ptk/UpdateEvent (update [_ state] (-> state - (update :workspace-data cp/process-changes changes) (assoc-in [:workspace-undo :index] index))))) (defn- add-undo-entry