From 20e4562c0905f7e94e3de6059a0320d5fd1f3ba2 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 26 Mar 2021 10:41:27 +0100 Subject: [PATCH] :bug: Fixed some issues when shift-selecting on sidebars --- common/app/common/pages/helpers.cljc | 22 ++++++++++--------- frontend/src/app/main/data/workspace.cljs | 3 ++- .../app/main/ui/workspace/shapes/outline.cljs | 4 ++-- .../src/app/main/ui/workspace/viewport.cljs | 3 ++- .../main/ui/workspace/viewport/selection.cljs | 8 ++++++- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/common/app/common/pages/helpers.cljc b/common/app/common/pages/helpers.cljc index d47a38383..2a5ba99aa 100644 --- a/common/app/common/pages/helpers.cljc +++ b/common/app/common/pages/helpers.cljc @@ -187,16 +187,18 @@ (defn clean-loops "Clean a list of ids from circular references." [objects ids] - (loop [ids ids - id (first ids) - others (rest ids)] - (if-not id - ids - (recur (cond-> ids - (some #(contains? ids %) (get-parents id objects)) - (disj id)) - (first others) - (rest others))))) + (let [parent-selected? + (fn [id] + (let [parents (get-parents id objects)] + (some ids parents))) + + add-element + (fn [result id] + (cond-> result + (not (parent-selected? id)) + (conj id)))] + + (reduce add-element (d/ordered-set) ids))) (defn calculate-invalid-targets [shape-id objects] diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 61b51eebb..b29c43bd0 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1352,7 +1352,8 @@ ptk/WatchEvent (watch [_ state stream] (let [objects (dwc/lookup-page-objects state) - selected (get-in state [:workspace-local :selected]) + selected (->> (get-in state [:workspace-local :selected]) + (cp/clean-loops objects)) pdata (reduce (partial collect-object-ids objects) {} selected) initial {:type :copied-shapes :file-id (:current-file-id state) diff --git a/frontend/src/app/main/ui/workspace/shapes/outline.cljs b/frontend/src/app/main/ui/workspace/shapes/outline.cljs index 13ad2d5a6..58b8b7d56 100644 --- a/frontend/src/app/main/ui/workspace/shapes/outline.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/outline.cljs @@ -20,8 +20,8 @@ (mf/defc outline {::mf/wrap-props false} [props] - (let [zoom (mf/deref refs/selected-zoom) - shape (unchecked-get props "shape") + (let [shape (unchecked-get props "shape") + zoom (unchecked-get props "zoom") color (unchecked-get props "color") transform (gsh/transform-matrix shape) path? (= :path (:type shape)) diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index 04849970d..3962ae83a 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -202,7 +202,8 @@ :selected selected :hover (when (not= :frame (:type @hover)) #{(or @frame-hover (:id @hover))}) - :edition edition}]) + :edition edition + :zoom zoom}]) (when show-selection-handlers? [:& selection/selection-handlers diff --git a/frontend/src/app/main/ui/workspace/viewport/selection.cljs b/frontend/src/app/main/ui/workspace/viewport/selection.cljs index 16b5edfbb..d9a5a2522 100644 --- a/frontend/src/app/main/ui/workspace/viewport/selection.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/selection.cljs @@ -296,7 +296,13 @@ (mf/defc multiple-selection-handlers [{:keys [shapes selected zoom color show-distances disable-handlers on-move-selected] :as props}] - (let [shape (geom/setup {:type :rect} (geom/selection-rect (->> shapes (map geom/transform-shape)))) + (let [shape (mf/use-memo + (mf/deps shapes) + #(->> shapes + (map geom/transform-shape) + (geom/selection-rect) + (geom/setup {:type :rect}))) + shape-center (geom/center-shape shape) hover-id (-> (mf/deref refs/current-hover) first)