From 68e3d53cb714391456afa70d11b444d1b3ae6ef1 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 4 Oct 2021 10:51:13 +0200 Subject: [PATCH] :bug: Fix problem with move+alt --- .../app/main/data/workspace/selection.cljs | 4 +- .../app/main/data/workspace/shortcuts.cljs | 2 +- .../app/main/data/workspace/transforms.cljs | 2 +- .../app/main/ui/workspace/context_menu.cljs | 2 +- .../app/main/ui/workspace/viewport/hooks.cljs | 37 ++++++++++++------- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/frontend/src/app/main/data/workspace/selection.cljs b/frontend/src/app/main/data/workspace/selection.cljs index 86208467f..55ea9aac8 100644 --- a/frontend/src/app/main/data/workspace/selection.cljs +++ b/frontend/src/app/main/data/workspace/selection.cljs @@ -428,14 +428,14 @@ delta (gpt/subtract new-pos (gpt/point obj))] delta)))) -(def duplicate-selected +(defn duplicate-selected [move-delta?] (ptk/reify ::duplicate-selected ptk/WatchEvent (watch [it state _] (let [page-id (:current-page-id state) objects (wsh/lookup-page-objects state page-id) selected (wsh/lookup-selected state) - delta (if (= (count selected) 1) + delta (if (and move-delta? (= (count selected) 1)) (let [obj (get objects (first selected))] (calc-duplicate-delta obj state objects)) (gpt/point 0 0)) diff --git a/frontend/src/app/main/data/workspace/shortcuts.cljs b/frontend/src/app/main/data/workspace/shortcuts.cljs index 34c5779ef..87d4735a7 100644 --- a/frontend/src/app/main/data/workspace/shortcuts.cljs +++ b/frontend/src/app/main/data/workspace/shortcuts.cljs @@ -119,7 +119,7 @@ :duplicate {:tooltip (ds/meta "D") :command (ds/c-mod "d") - :fn #(st/emit! dw/duplicate-selected)} + :fn #(st/emit! (dw/duplicate-selected true))} :undo {:tooltip (ds/meta "Z") :command (ds/c-mod "z") diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index 9426033c8..b6f660ea4 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -505,7 +505,7 @@ (if alt? ;; When alt is down we start a duplicate+move (rx/of (start-move-duplicate initial) - dws/duplicate-selected) + (dws/duplicate-selected false)) ;; Otherwise just plain old move (rx/of (start-move initial selected))))))))))) diff --git a/frontend/src/app/main/ui/workspace/context_menu.cljs b/frontend/src/app/main/ui/workspace/context_menu.cljs index 3ed95846f..3274be1b0 100644 --- a/frontend/src/app/main/ui/workspace/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/context_menu.cljs @@ -109,7 +109,7 @@ current-file-id (mf/use-ctx ctx/current-file-id) - do-duplicate (st/emitf dw/duplicate-selected) + do-duplicate (st/emitf (dw/duplicate-selected false)) do-delete (st/emitf dw/delete-selected) do-copy (st/emitf (dw/copy-selected)) do-cut (st/emitf (dw/copy-selected) dw/delete-selected) diff --git a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs index aab5f7f08..b9df6b983 100644 --- a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs @@ -117,10 +117,16 @@ over-shapes-stream (mf/use-memo (fn [] - (->> move-stream - ;; When transforming shapes we stop querying the worker - (rx/filter #(not (some? (mf/ref-val transform-ref)))) - (rx/switch-map query-point))))] + (rx/merge + (->> move-stream + ;; When transforming shapes we stop querying the worker + (rx/filter #(not (some? (mf/ref-val transform-ref)))) + (rx/switch-map query-point)) + + (->> move-stream + ;; When transforming shapes we stop querying the worker + (rx/filter #(some? (mf/ref-val transform-ref))) + (rx/map (constantly nil))))))] ;; Refresh the refs on a value change (mf/use-effect @@ -147,19 +153,22 @@ over-shapes-stream (mf/deps page-id objects @ctrl?) (fn [ids] - (let [selected (mf/ref-val selected-ref) - remove-id? (into #{} (mapcat #(cp/get-parents % objects)) selected) - - is-group? + (let [is-group? (fn [id] (contains? #{:group :bool} (get-in objects [id :type]))) - remove-id? - (if @ctrl? - (d/concat remove-id? (filterv is-group? ids)) - remove-id?) - ids (->> ids (filterv (comp not remove-id?)))] - (reset! hover (get objects (first ids))) + selected (mf/ref-val selected-ref) + + remove-xfm (mapcat #(cp/get-parents % objects)) + remove-id? (cond-> (into #{} remove-xfm selected) + @ctrl? + (d/concat (filterv is-group? ids))) + + ids (->> ids (filterv (comp not remove-id?))) + + hover-shape (get objects (first ids))] + + (reset! hover hover-shape) (reset! hover-ids ids)))))) (defn setup-viewport-modifiers [modifiers selected objects render-ref]