From b5b97f762640837a3d00b02ba5927c6032444700 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 3 Sep 2021 14:52:05 +0200 Subject: [PATCH] :bug: Fix problem with multiple selection conflicting with hover --- .../app/main/data/workspace/selection.cljs | 20 +++++++++---------- .../src/app/main/ui/workspace/viewport.cljs | 2 +- .../app/main/ui/workspace/viewport/hooks.cljs | 13 ++++++++---- frontend/src/app/util/worker.cljs | 2 +- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/frontend/src/app/main/data/workspace/selection.cljs b/frontend/src/app/main/data/workspace/selection.cljs index 0847cc5b5..912f0fa8d 100644 --- a/frontend/src/app/main/data/workspace/selection.cljs +++ b/frontend/src/app/main/data/workspace/selection.cljs @@ -219,17 +219,15 @@ lks/empty-linked-set) selrect (get-in state [:workspace-local :selrect]) blocked? (fn [id] (get-in objects [id :blocked] false))] - (rx/merge - - (when selrect - (->> (uw/ask! {:cmd :selection/query - :page-id page-id - :rect selrect - :include-frames? true - :full-frame? true}) - (rx/map #(cp/clean-loops objects %)) - (rx/map #(into initial-set (filter (comp not blocked?)) %)) - (rx/map select-shapes)))))))) + (when selrect + (->> (uw/ask! {:cmd :selection/query + :page-id page-id + :rect selrect + :include-frames? true + :full-frame? true}) + (rx/map #(cp/clean-loops objects %)) + (rx/map #(into initial-set (filter (comp not blocked?)) %)) + (rx/map select-shapes))))))) (defn select-inside-group [group-id position] diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index f73a40c3e..c989136b5 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -153,7 +153,7 @@ (hooks/setup-cursor cursor alt? panning drawing-tool drawing-path? node-editing?) (hooks/setup-resize layout viewport-ref) (hooks/setup-keyboard alt? ctrl? space?) - (hooks/setup-hover-shapes page-id move-stream selected objects transform selected ctrl? hover hover-ids zoom) + (hooks/setup-hover-shapes page-id move-stream objects transform selected ctrl? hover hover-ids zoom) (hooks/setup-viewport-modifiers modifiers selected objects render-ref) (hooks/setup-shortcuts node-editing? drawing-path?) (hooks/setup-active-frames objects vbox hover active-frames) diff --git a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs index d00b75566..9bebb02bd 100644 --- a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs @@ -89,11 +89,11 @@ (hooks/use-stream ms/keyboard-ctrl #(reset! ctrl? %)) (hooks/use-stream ms/keyboard-space #(reset! space? %))) -;; TODO: revisit the arguments, looks like `selected` is not necessary here -(defn setup-hover-shapes [page-id move-stream _selected objects transform selected ctrl? hover hover-ids zoom] +(defn setup-hover-shapes [page-id move-stream objects transform selected ctrl? hover hover-ids zoom] (let [;; We use ref so we don't recreate the stream on a change zoom-ref (mf/use-ref zoom) transform-ref (mf/use-ref nil) + selected-ref (mf/use-ref selected) query-point (mf/use-callback @@ -127,11 +127,16 @@ (mf/deps zoom) #(mf/set-ref-val! zoom-ref zoom)) + (mf/use-effect + (mf/deps selected) + #(mf/set-ref-val! selected-ref selected)) + (hooks/use-stream over-shapes-stream - (mf/deps page-id objects selected @ctrl?) + (mf/deps page-id objects @ctrl?) (fn [ids] - (let [remove-id? (into #{} (mapcat #(cp/get-parents % objects)) selected) + (let [selected (mf/ref-val selected-ref) + remove-id? (into #{} (mapcat #(cp/get-parents % objects)) selected) remove-id? (if @ctrl? (d/concat remove-id? (->> ids diff --git a/frontend/src/app/util/worker.cljs b/frontend/src/app/util/worker.cljs index 810d32e29..914756e96 100644 --- a/frontend/src/app/util/worker.cljs +++ b/frontend/src/app/util/worker.cljs @@ -62,7 +62,7 @@ [path on-error] (let [instance (js/Worker. path) bus (rx/subject) - worker (Worker. instance bus) + worker (Worker. instance (rx/to-observable bus)) handle-message (fn [event]