diff --git a/frontend/src/app/worker/selection.cljs b/frontend/src/app/worker/selection.cljs index d82daf51f..b78f3c7f1 100644 --- a/frontend/src/app/worker/selection.cljs +++ b/frontend/src/app/worker/selection.cljs @@ -57,30 +57,34 @@ {:index index :z-index z-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] - (not= (get old-objects id) - (get new-objects id))) + (if (some? data) + (let [changes? (fn [id] + (not= (get old-objects id) + (get new-objects id))) - changed-ids (into #{} - (filter changes?) - (set/union (keys old-objects) - (keys new-objects))) + changed-ids (into #{} + (filter changes?) + (set/union (keys old-objects) + (keys new-objects))) - shapes (->> changed-ids (mapv #(get new-objects %)) (filterv (comp not nil?))) - parents-index (cp/generate-child-all-parents-index new-objects shapes) - masks-index (cp/create-mask-index new-objects parents-index) + shapes (->> changed-ids (mapv #(get new-objects %)) (filterv (comp not nil?))) + parents-index (cp/generate-child-all-parents-index new-objects shapes) + 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) - new-index - shapes) + index (reduce (index-shape new-objects parents-index masks-index) + new-index + 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 [{index :index z-index :z-index} rect frame-id include-frames? include-groups? disabled-masks reverse?] diff --git a/frontend/src/app/worker/snaps.cljs b/frontend/src/app/worker/snaps.cljs index f67e64890..aa531dd4f 100644 --- a/frontend/src/app/worker/snaps.cljs +++ b/frontend/src/app/worker/snaps.cljs @@ -39,16 +39,15 @@ (rt/insert tree (coord point) data))] (->> shapes (mapcat (process-shape frame-id coord)) - (reduce into-tree data)))) + (reduce into-tree (or data (rt/make-tree)))))) (defn remove-coord-data [data frame-id shapes coord] - (letfn [(remove-tree [tree [point _ :as data]] (rt/remove tree (coord point) data))] (->> shapes (mapcat (process-shape frame-id coord)) - (reduce remove-tree data)))) + (reduce remove-tree (or data (rt/make-tree)))))) (defn aggregate-data ([objects] @@ -117,16 +116,13 @@ add-frames (fn [snap-data frame-id] (assoc snap-data frame-id {:x (rt/make-tree) - :y (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)) + (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)))) (defn- log-state "Helper function to print a friendly version of the snap tree. Debugging purposes"