From 8cf2d4f3a4ed5bee736aa3d25c2a9efb94602b46 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 23 Mar 2021 11:55:22 +0100 Subject: [PATCH] :bug: Fixes some problems with shapes selection --- .../src/app/main/ui/workspace/viewport.cljs | 4 +- .../main/ui/workspace/viewport/actions.cljs | 62 ++++++++++++------- 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index eb9515f49..04849970d 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -89,7 +89,7 @@ drawing-path? (and edition (= :draw (get-in edit-path [edition :edit-mode]))) text-editing? (and edition (= :text (get-in objects [edition :type]))) - on-click (actions/on-click) + on-click (actions/on-click hover selected) on-context-menu (actions/on-context-menu hover) on-double-click (actions/on-double-click hover hover-ids objects) on-drag-enter (actions/on-drag-enter) @@ -102,7 +102,7 @@ on-pointer-leave (actions/on-pointer-leave in-viewport?) on-pointer-move (actions/on-pointer-move viewport-ref zoom move-stream) on-pointer-up (actions/on-pointer-up) - on-move-selected (actions/on-move-selected hover selected) + on-move-selected (actions/on-move-selected hover hover-ids selected) on-frame-enter (actions/on-frame-enter frame-hover) on-frame-leave (actions/on-frame-leave frame-hover) diff --git a/frontend/src/app/main/ui/workspace/viewport/actions.cljs b/frontend/src/app/main/ui/workspace/viewport/actions.cljs index 99eea2007..b8ca894f1 100644 --- a/frontend/src/app/main/ui/workspace/viewport/actions.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/actions.cljs @@ -76,18 +76,19 @@ (dw/start-move-selected)))))))))) (defn on-move-selected - [hover selected] + [hover hover-ids selected] (mf/use-callback - (mf/deps @hover selected) + (mf/deps @hover @hover-ids selected) (fn [bevent] (let [event (.-nativeEvent bevent) shift? (kbd/shift? event) left-click? (= 1 (.-which event))] + (when (and left-click? (not shift?) (or (not @hover) - (contains? selected (:id @hover)) - (contains? selected (:frame-id @hover)))) + (= :frame (:type @hover)) + (some #(contains? selected %) @hover-ids))) (dom/prevent-default bevent) (dom/stop-propagation bevent) (st/emit! (dw/start-move-selected))))))) @@ -117,13 +118,21 @@ (reset! frame-hover nil)))) (defn on-click - [] + [hover selected] (mf/use-callback + (mf/deps @hover selected) (fn [event] (let [ctrl? (kbd/ctrl? event) shift? (kbd/shift? event) - alt? (kbd/alt? event)] - (st/emit! (ms/->MouseEvent :click ctrl? shift? alt?)))))) + alt? (kbd/alt? event) + + hovering? (some? @hover) + frame? (= :frame (:type @hover)) + selected? (contains? selected (:id @hover))] + (st/emit! (ms/->MouseEvent :click ctrl? shift? alt?)) + + (when (and hovering? (not shift?) (not frame?) (not selected?)) + (st/emit! (dw/select-shape (:id @hover)))))))) (defn on-double-click [hover hover-ids objects] @@ -163,14 +172,19 @@ (defn on-context-menu [hover] - (let [{:keys [id]} @hover] - (mf/use-callback - (mf/deps id) - (fn [event] - (dom/prevent-default event) - (let [position (dom/get-client-position event)] - (st/emit! (dw/show-context-menu {:position position - :shape @hover}))))))) + (mf/use-callback + (mf/deps @hover) + (fn [event] + (dom/prevent-default event) + + (let [position (dom/get-client-position event)] + ;; Delayed callback because we need to wait to the previous context menu to be closed + (timers/schedule + #(st/emit! + (if (some? @hover) + (dw/show-shape-context-menu {:position position + :shape @hover}) + (dw/show-context-menu {:position position})))))))) (defn on-mouse-up [disable-paste] @@ -231,18 +245,20 @@ (defn on-key-down [] (mf/use-callback (fn [event] - (let [bevent (.getBrowserEvent ^js event) - key (.-keyCode ^js event) - key (.normalizeKeyCode KeyCodes key) - ctrl? (kbd/ctrl? event) - shift? (kbd/shift? event) - alt? (kbd/alt? event) - meta? (kbd/meta? event) - target (dom/get-target event)] + (let [bevent (.getBrowserEvent ^js event) + key (.-keyCode ^js event) + key (.normalizeKeyCode KeyCodes key) + ctrl? (kbd/ctrl? event) + shift? (kbd/shift? event) + alt? (kbd/alt? event) + meta? (kbd/meta? event) + target (dom/get-target event) + editor? (some? (.closest ^js target ".public-DraftEditor-content"))] (when-not (.-repeat bevent) (st/emit! (ms/->KeyboardEvent :down key shift? ctrl? alt? meta?)) (when (and (kbd/space? event) + (not editor?) (not= "rich-text" (obj/get target "className")) (not= "INPUT" (obj/get target "tagName")) (not= "TEXTAREA" (obj/get target "tagName")))