From c1278194ce17fb7d87736a281b24ea2020427523 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 7 May 2021 14:42:13 +0200 Subject: [PATCH] :bug: Fix snap index problem --- CHANGES.md | 1 + frontend/src/app/worker/snaps.cljs | 34 ++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3c8d5d553..aecc5d190 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ ### :bug: Bugs fixed - Remove interactions when the destination artboard is deleted [Taiga #1656](https://tree.taiga.io/project/penpot/issue/1656) +- Fix snap index problem [Taiga #1661](https://tree.taiga.io/project/penpot/issue/1661) ### :arrow_up: Deps updates ### :boom: Breaking changes diff --git a/frontend/src/app/worker/snaps.cljs b/frontend/src/app/worker/snaps.cljs index 9cd78cec0..f67e64890 100644 --- a/frontend/src/app/worker/snaps.cljs +++ b/frontend/src/app/worker/snaps.cljs @@ -69,8 +69,9 @@ (let [shapes-data (aggregate-data objects) create-index - (fn [frame-id shapes] {:x (add-coord-data (rt/make-tree) frame-id shapes :x) - :y (add-coord-data (rt/make-tree) frame-id shapes :y)})] + (fn [frame-id shapes] + {:x (-> (rt/make-tree) (add-coord-data frame-id shapes :x)) + :y (-> (rt/make-tree) (add-coord-data frame-id shapes :y))})] (d/mapm create-index shapes-data))) @@ -78,6 +79,14 @@ [snap-data old-objects new-objects] (let [changed? #(not= (get old-objects %) (get new-objects %)) + is-deleted-frame? #(and (not= uuid/zero %) + (contains? old-objects %) + (not (contains? new-objects %)) + (= :frame (get-in old-objects [% :type]))) + is-new-frame? #(and (not= uuid/zero %) + (contains? new-objects %) + (not (contains? old-objects %)) + (= :frame (get-in new-objects [% :type]))) changed-ids (into #{} (filter changed?) @@ -86,6 +95,9 @@ to-delete (aggregate-data old-objects changed-ids) to-add (aggregate-data new-objects changed-ids) + frames-to-delete (->> changed-ids (filter is-deleted-frame?)) + frames-to-add (->> changed-ids (filter is-new-frame?)) + delete-data (fn [snap-data [frame-id shapes]] (-> snap-data @@ -98,11 +110,21 @@ (update-in [frame-id :x] add-coord-data frame-id shapes :x) (update-in [frame-id :y] add-coord-data frame-id shapes :y))) - snap-data (->> to-delete - (reduce delete-data snap-data)) + delete-frames + (fn [snap-data frame-id] + (dissoc snap-data frame-id)) - snap-data (->> to-add - (reduce add-data snap-data))] + add-frames + (fn [snap-data frame-id] + (assoc snap-data frame-id {:x (rt/make-tree) + :y (rt/make-tree)})) + + snap-data (as-> snap-data $ + (reduce add-frames $ frames-to-add) + (reduce add-data $ to-add) + (reduce delete-data $ to-delete) + (reduce delete-frames $ frames-to-delete)) + ] snap-data))