From eaa6327663d77b5ef50e4cd50e90562112ee9312 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 31 Mar 2022 11:03:14 +0200 Subject: [PATCH] :bug: Fix issue with drag-select shapes --- CHANGES.md | 1 + frontend/src/app/main/data/workspace/selection.cljs | 5 ++++- frontend/src/app/main/ui/workspace/viewport.cljs | 2 +- frontend/src/app/main/ui/workspace/viewport/actions.cljs | 9 +++++---- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d8f2b61f6..833f76de8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ ### :bug: Bugs fixed - Fix issue with shift+select to deselect shapes [Taiga #3154](https://tree.taiga.io/project/penpot/issue/3154) +- Fix issue with drag-select shapes [Taiga #3165](https://tree.taiga.io/project/penpot/issue/3165) ## 1.12.2-beta diff --git a/frontend/src/app/main/data/workspace/selection.cljs b/frontend/src/app/main/data/workspace/selection.cljs index 08f2985e5..001bc27c4 100644 --- a/frontend/src/app/main/data/workspace/selection.cljs +++ b/frontend/src/app/main/data/workspace/selection.cljs @@ -104,7 +104,10 @@ (rx/dedupe) (rx/map #(select-shapes-by-current-selrect preserve? ignore-groups?)))) - (rx/of (update-selrect nil))))))) + (->> (rx/of (update-selrect nil)) + ;; We need the async so the current event finishes before updating the selrect + ;; otherwise the `on-click` event will trigger with a `nil` selrect + (rx/observe-on :async))))))) ;; --- Toggle shape's selection status (selected or deselected) diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index 943f796c4..a0d0c740f 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -116,7 +116,7 @@ node-editing? (and edition (not= :text (get-in base-objects [edition :type]))) text-editing? (and edition (= :text (get-in base-objects [edition :type]))) - on-click (actions/on-click hover selected edition drawing-path? drawing-tool space?) + on-click (actions/on-click hover selected edition drawing-path? drawing-tool space? selrect) on-context-menu (actions/on-context-menu hover hover-ids) on-double-click (actions/on-double-click hover hover-ids drawing-path? base-objects edition) on-drag-enter (actions/on-drag-enter) diff --git a/frontend/src/app/main/ui/workspace/viewport/actions.cljs b/frontend/src/app/main/ui/workspace/viewport/actions.cljs index bb273a51a..6ac904151 100644 --- a/frontend/src/app/main/ui/workspace/viewport/actions.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/actions.cljs @@ -142,12 +142,13 @@ (reset! frame-hover nil)))) (defn on-click - [hover selected edition drawing-path? drawing-tool space?] + [hover selected edition drawing-path? drawing-tool space? selrect] (mf/use-callback - (mf/deps @hover selected edition drawing-path? drawing-tool @space?) + (mf/deps @hover selected edition drawing-path? drawing-tool @space? selrect) (fn [event] - (when (or (dom/class? (dom/get-target event) "viewport-controls") - (dom/class? (dom/get-target event) "viewport-selrect")) + (when (and (nil? selrect) + (or (dom/class? (dom/get-target event) "viewport-controls") + (dom/class? (dom/get-target event) "viewport-selrect"))) (let [ctrl? (kbd/ctrl? event) shift? (kbd/shift? event) alt? (kbd/alt? event)