From 688ec2589a9795ce05fc005f5556e24fb63533e2 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 31 May 2022 21:32:51 +0200 Subject: [PATCH] :sparkles: Changes in selection feedback --- frontend/src/app/main/data/workspace.cljs | 4 +-- frontend/src/app/main/refs.cljs | 7 ++-- .../src/app/main/ui/workspace/viewport.cljs | 14 ++++---- .../main/ui/workspace/viewport/actions.cljs | 7 ++-- .../app/main/ui/workspace/viewport/hooks.cljs | 36 +++++++++++++------ 5 files changed, 41 insertions(+), 27 deletions(-) diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index abb8c2244..ef20955e1 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1224,8 +1224,8 @@ ;; (+ (get z-index %) ;; (get z-index (get-in objects [% :frame-id])))))) - selected (-> (cph/sort-z-index objects selected) - (into (d/ordered-set)))] + selected (->> (cph/sort-z-index objects selected) + (into (d/ordered-set)))] (assoc data :selected selected))) diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 91117c622..4e6998827 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -306,8 +306,11 @@ (fn [{:keys [modifiers objects]}] (let [keys (->> modifiers (keys) - (filter #(or (= frame-id %) - (= frame-id (get-in objects [% :frame-id])))))] + (filter (fn [id] + (let [shape (get objects id)] + (or (= frame-id id) + (and (= frame-id (:frame-id shape)) + (not (= :frame (:type shape)))))))))] (select-keys modifiers keys))) workspace-modifiers-with-objects =)) diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index 38b2b7e1f..1f55733c0 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -155,7 +155,12 @@ show-draw-area? drawing-obj show-gradient-handlers? (= (count selected) 1) show-grids? (contains? layout :display-grid) - show-outlines? (and (nil? transform) (not edition) (not drawing-obj) (not (#{:comments :path :curve} drawing-tool))) + + show-outlines? (and (nil? transform) + (not edition) + (not drawing-obj) + (not (#{:comments :path :curve} drawing-tool))) + show-pixel-grid? (and (contains? layout :show-pixel-grid) (>= zoom 8)) show-text-editor? (and editing-shape (= :text (:type editing-shape))) @@ -279,12 +284,7 @@ [:& outline/shape-outlines {:objects base-objects :selected selected - :hover (cond - (and @hover (or @mod? (not= :frame (:type @hover)))) - #{(:id @hover)} - - @frame-hover - #{@frame-hover}) + :hover #{(:id @hover) @frame-hover} :edition edition :zoom zoom}]) diff --git a/frontend/src/app/main/ui/workspace/viewport/actions.cljs b/frontend/src/app/main/ui/workspace/viewport/actions.cljs index 32aaf6e0c..5501998e6 100644 --- a/frontend/src/app/main/ui/workspace/viewport/actions.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/actions.cljs @@ -52,7 +52,6 @@ left-click? (and (not panning) (= 1 (.-which event))) middle-click? (and (not panning) (= 2 (.-which event))) - frame? (= :frame type) selected? (contains? selected id)] (cond @@ -96,7 +95,7 @@ drawing-tool (st/emit! (dd/start-drawing drawing-tool)) - (or (not id) (and frame? (not selected?)) mod?) + (or (not id) mod?) (st/emit! (dw/handle-area-selection shift? mod?)) (not drawing-tool) @@ -157,12 +156,10 @@ alt? (kbd/alt? event) meta? (kbd/meta? event) mod? (kbd/mod? event) - hovering? (some? @hover) - frame? (= :frame (:type @hover))] + hovering? (some? @hover)] (st/emit! (ms/->MouseEvent :click ctrl? shift? alt? meta?)) (when (and hovering? - (or (not frame?) mod?) (not @space?) (not edition) (not drawing-path?) diff --git a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs index dd4123d48..71da7118d 100644 --- a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs @@ -10,6 +10,7 @@ [app.common.pages :as cp] [app.common.pages.helpers :as cph] [app.common.uuid :as uuid] + [app.common.data :as d] [app.main.data.shortcuts :as dsc] [app.main.data.workspace :as dw] [app.main.data.workspace.path.shortcuts :as psc] @@ -112,6 +113,9 @@ hover-disabled-ref (mf/use-ref hover-disabled?) focus-ref (mf/use-ref focus) + last-point-ref (mf/use-var nil) + mod-str (mf/use-memo #(rx/subject)) + query-point (mf/use-callback (mf/deps page-id) @@ -133,15 +137,23 @@ (mf/use-memo (fn [] (rx/merge + ;; This stream works to "refresh" the outlines when the control is pressed + ;; but the mouse has not been moved from its position. + (->> mod-str + (rx/observe-on :async) + (rx/map #(deref last-point-ref))) + (->> move-stream ;; When transforming shapes we stop querying the worker (rx/filter #(not (some? (mf/ref-val transform-ref)))) - (rx/merge-map query-point)) + (rx/merge-map query-point) + (rx/tap #(reset! last-point-ref %))) (->> move-stream ;; When transforming shapes we stop querying the worker (rx/filter #(some? (mf/ref-val transform-ref))) - (rx/map (constantly nil))))))] + (rx/map (constantly nil)) + (rx/tap #(reset! last-point-ref %))))))] ;; Refresh the refs on a value change (mf/use-effect @@ -154,7 +166,9 @@ (mf/use-effect (mf/deps @mod?) - #(mf/set-ref-val! mod-ref @mod?)) + (fn [] + (rx/push! mod-str :update) + (mf/set-ref-val! mod-ref @mod?))) (mf/use-effect (mf/deps selected) @@ -172,10 +186,11 @@ over-shapes-stream (mf/deps page-id objects) (fn [ids] - #_(prn "??hover-ids" (->> ids (map #(get-in objects [% :name])))) - (let [is-group? - (fn [id] - (contains? #{:group :bool} (get-in objects [id :type]))) + (let [ids (into + (d/ordered-set) + (cph/sort-z-index objects ids)) + + grouped? (fn [id] (contains? #{:group :bool} (get-in objects [id :type]))) selected (mf/ref-val selected-ref) focus (mf/ref-val focus-ref) @@ -188,12 +203,11 @@ (into (filter #(group-empty-space? % objects ids)) ids) mod? - (into (filter is-group?) ids)) + (into (filter grouped?) ids)) hover-shape (->> ids - (filter (comp not remove-id?)) - (filter #(or (empty? focus) - (cp/is-in-focus? objects focus %))) + (remove remove-id?) + (filter #(or (empty? focus) (cp/is-in-focus? objects focus %))) (first) (get objects))] (reset! hover hover-shape)