Repository: penpot/penpot
File: frontend/src/app/main/data/workspace/selection.cljs (ClojureScript)

Code before:
                (rt/nav :workspace params-without-board {::rt/replace true}))))

     ptk/UpdateEvent
     (update [_ state]

       ;; Only deselect if there is no modal opened
       (cond-> state
         (or (not check-modal)
             (not (::md/modal state)))
         (update :workspace-local
                 #(-> %
                      (assoc :selected (d/ordered-set))
                      (dissoc :selected-frame))))))))

;; --- Select Shapes (By selrect)

(defn select-shapes-by-current-selrect
  ([preserve? ignore-groups?]
   (select-shapes-by-current-selrect preserve? ignore-groups? true))
  ([preserve? ignore-groups? buffered?]
   (ptk/reify ::select-shapes-by-current-selrect
     ptk/WatchEvent
     (watch [_ state _]
       (let [page-id     (:current-page-id state)
             objects     (dsh/lookup-page-objects state)
             selected    (dsh/lookup-selected state)
             initial-set (if preserve?
                           selected
                           lks/empty-linked-set)
             selrect     (dm/get-in state [:workspace-local :selrect])
             blocked?    (fn [id] (dm/get-in objects [id :blocked] false))

             ask-worker (if buffered? mw/ask-buffered! mw/ask!)]

         (if (some? selrect)
           (->> (ask-worker
                 {:cmd :selection/query
                  :page-id page-id
                  :rect selrect
                  :include-frames? true
                  :ignore-groups? ignore-groups?
                  :full-frame? true
                  :using-selrect? true})
                (rx/filter some?)
                (rx/map #(cfh/clean-loops objects %))
                (rx/map #(into initial-set (comp
                                            (filter (complement blocked?))
                                            (remove (partial cfh/hidden-parent? objects))) %))
                (rx/map select-shapes))
           (rx/empty)))))))


Review comment (suggestion):
as you already have the page-id, you can pass it to the `dsh/lookup-page-objects` second argument for avoid double lookup. I know is not your code, but as we already touching this code, it is better to fix that also.

Code after:
     ptk/UpdateEvent
     (update [_ state]

       ;; Only deselect if there is no modal opened
       (cond-> state
         (or (not check-modal)
             (not (::md/modal state)))
         (update :workspace-local
                 #(-> %
                      (assoc :selected (d/ordered-set))
                      (dissoc :selected-frame))))))))

;; --- Select Shapes (By selrect)

(defn select-shapes-by-current-selrect
  "Sends the current selection rectangle to the worker to compute the selection,
  and sends its result to select-shapes for storage in the state."
  ([initial-set remove? ignore-groups?]
   (select-shapes-by-current-selrect initial-set remove? ignore-groups? true))

  ([initial-set remove? ignore-groups? buffered?]
   (ptk/reify ::select-shapes-by-current-selrect
     ptk/WatchEvent
     (watch [_ state _]
       (let [page-id (:current-page-id state)
             objects (dsh/lookup-page-objects state)
             selrect (dm/get-in state [:workspace-local :selrect])
             blocked? (fn [id] (dm/get-in objects [id :blocked] false))
             ask-worker (if buffered? mw/ask-buffered! mw/ask!)
             filter-objs (comp
                          (filter (complement blocked?))
                          (remove (partial cfh/hidden-parent? objects)))]

         (if (some? selrect)
           (->> (ask-worker
                 {:cmd :selection/query
                  :page-id page-id
                  :rect selrect
                  :include-frames? true
                  :ignore-groups? ignore-groups?
                  :full-frame? true
                  :using-selrect? true})
                (rx/filter some?)
                (rx/map #(cfh/clean-loops objects %))
                (rx/map (if remove?
                          #(apply disj initial-set %)
                          #(into initial-set filter-objs %)))
                (rx/map select-shapes))
           (rx/empty)))))))

(defn select-inside-group