0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-12 15:51:37 -05:00

🐛 Fixes problem recreating indices

This commit is contained in:
alonso.torres 2021-05-10 09:55:37 +02:00 committed by Andrey Antukh
parent 0cc600de6d
commit 7033ae4f2e
2 changed files with 29 additions and 29 deletions

View file

@ -57,30 +57,34 @@
{:index index :z-index z-index})) {:index index :z-index z-index}))
(defn- update-index (defn- update-index
[{index :index z-index :z-index} old-objects new-objects] [{index :index z-index :z-index :as data} old-objects new-objects]
(let [changes? (fn [id] (if (some? data)
(not= (get old-objects id) (let [changes? (fn [id]
(get new-objects id))) (not= (get old-objects id)
(get new-objects id)))
changed-ids (into #{} changed-ids (into #{}
(filter changes?) (filter changes?)
(set/union (keys old-objects) (set/union (keys old-objects)
(keys new-objects))) (keys new-objects)))
shapes (->> changed-ids (mapv #(get new-objects %)) (filterv (comp not nil?))) shapes (->> changed-ids (mapv #(get new-objects %)) (filterv (comp not nil?)))
parents-index (cp/generate-child-all-parents-index new-objects shapes) parents-index (cp/generate-child-all-parents-index new-objects shapes)
masks-index (cp/create-mask-index new-objects parents-index) masks-index (cp/create-mask-index new-objects parents-index)
new-index (qdt/remove-all index changed-ids) new-index (qdt/remove-all index changed-ids)
index (reduce (index-shape new-objects parents-index masks-index) index (reduce (index-shape new-objects parents-index masks-index)
new-index new-index
shapes) shapes)
z-index (cp/update-z-index z-index changed-ids old-objects new-objects)] z-index (cp/update-z-index z-index changed-ids old-objects new-objects)]
{:index index :z-index z-index})) {:index index :z-index z-index})
;; If not previous data. We need to create from scratch
(create-index new-objects)))
(defn- query-index (defn- query-index
[{index :index z-index :z-index} rect frame-id include-frames? include-groups? disabled-masks reverse?] [{index :index z-index :z-index} rect frame-id include-frames? include-groups? disabled-masks reverse?]

View file

@ -39,16 +39,15 @@
(rt/insert tree (coord point) data))] (rt/insert tree (coord point) data))]
(->> shapes (->> shapes
(mapcat (process-shape frame-id coord)) (mapcat (process-shape frame-id coord))
(reduce into-tree data)))) (reduce into-tree (or data (rt/make-tree))))))
(defn remove-coord-data (defn remove-coord-data
[data frame-id shapes coord] [data frame-id shapes coord]
(letfn [(remove-tree [tree [point _ :as data]] (letfn [(remove-tree [tree [point _ :as data]]
(rt/remove tree (coord point) data))] (rt/remove tree (coord point) data))]
(->> shapes (->> shapes
(mapcat (process-shape frame-id coord)) (mapcat (process-shape frame-id coord))
(reduce remove-tree data)))) (reduce remove-tree (or data (rt/make-tree))))))
(defn aggregate-data (defn aggregate-data
([objects] ([objects]
@ -117,16 +116,13 @@
add-frames add-frames
(fn [snap-data frame-id] (fn [snap-data frame-id]
(assoc snap-data frame-id {:x (rt/make-tree) (assoc snap-data frame-id {:x (rt/make-tree)
:y (rt/make-tree)})) :y (rt/make-tree)}))]
snap-data (as-> snap-data $ (as-> snap-data $
(reduce add-frames $ frames-to-add) (reduce add-frames $ frames-to-add)
(reduce add-data $ to-add) (reduce add-data $ to-add)
(reduce delete-data $ to-delete) (reduce delete-data $ to-delete)
(reduce delete-frames $ frames-to-delete)) (reduce delete-frames $ frames-to-delete))))
]
snap-data))
(defn- log-state (defn- log-state
"Helper function to print a friendly version of the snap tree. Debugging purposes" "Helper function to print a friendly version of the snap tree. Debugging purposes"