From 2ac8a32986472999147a8067e439ad6039245bb8 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 5 Jun 2020 15:31:13 +0200 Subject: [PATCH] :bug: Fixes some issues with dynamic alignment --- frontend/src/uxbox/main/snap.cljs | 1 + .../main/ui/workspace/snap_distances.cljs | 18 +++++++++++++----- frontend/src/uxbox/worker/selection.cljs | 13 ++++++++++--- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/frontend/src/uxbox/main/snap.cljs b/frontend/src/uxbox/main/snap.cljs index 239524d83..41b893aa4 100644 --- a/frontend/src/uxbox/main/snap.cljs +++ b/frontend/src/uxbox/main/snap.cljs @@ -150,6 +150,7 @@ (defn select-shapes-area [page-id shapes objects area-selrect] (->> (uw/ask! {:cmd :selection/query :page-id page-id + :frame-id (->> shapes first :frame-id) :rect area-selrect}) (rx/map #(set/difference % (into #{} (map :id shapes)))) (rx/map (fn [ids] (map #(get objects %) ids))))) diff --git a/frontend/src/uxbox/main/ui/workspace/snap_distances.cljs b/frontend/src/uxbox/main/ui/workspace/snap_distances.cljs index 8dfe91f09..c3c254540 100644 --- a/frontend/src/uxbox/main/ui/workspace/snap_distances.cljs +++ b/frontend/src/uxbox/main/ui/workspace/snap_distances.cljs @@ -129,6 +129,7 @@ query-side (fn [side] (->> (uw/ask! {:cmd :selection/query :page-id page-id + :frame-id (:id frame) :rect (gsh/pad-selrec (areas side))}) (rx/map #(set/difference % selected)) (rx/map #(->> % (map (partial get @refs/workspace-objects))))))] @@ -154,6 +155,12 @@ (map pair->distance+pair) (filter (comp pred? first)))) + ;; Checks if the value is in a set of numbers with an error margin of 0.1 + check-in-set + (fn [value number-set] + (->> number-set + (some #(<= (mth/abs (- value %)) 0.5)))) + ;; Left/Top shapes and right/bottom shapes (depends on `coord` parameter [lt-shapes gt-shapes] @to-measure @@ -161,8 +168,9 @@ lt-distances (->> lt-shapes (map distance-to-selrect) (filter pos?) (into #{})) gt-distances (->> gt-shapes (map distance-to-selrect) (filter pos?) (into #{})) + ;; We'll show the distances that match a distance from the selrect - show-candidate? (set/union lt-distances gt-distances) + show-candidate? #(check-in-set % (set/union lt-distances gt-distances)) ;; Checks the distances between elements for distances that match the set of distances distance-coincidences (concat (get-shapes-match show-candidate? lt-shapes) @@ -170,9 +178,9 @@ ;; Show the distances that either match one of the distances from the selrect ;; or are from the selrect and go to a shape on the left and to the right - show-distance? (into #{} (concat - (map first distance-coincidences) - (set/intersection lt-distances gt-distances))) + show-distance? #(check-in-set % (into #{} (concat + (map first distance-coincidences) + (set/intersection lt-distances gt-distances)))) ;; These are the segments whose distance will be displayed @@ -181,7 +189,7 @@ (map second) ;; Retrieves list of [shape,shape] tuples (map #(mapv :selrect %))) ;; Changes [shape,shape] to [selrec,selrec] - ;; Segments from the selection to other + ;; Segments from the selection to the other shapes selection-segments (->> (concat lt-shapes gt-shapes) (filter #(show-distance? (distance-to-selrect %))) (map #(vector selrect (:selrect %)))) diff --git a/frontend/src/uxbox/worker/selection.cljs b/frontend/src/uxbox/worker/selection.cljs index 9a285bf5a..e4ae865e8 100644 --- a/frontend/src/uxbox/worker/selection.cljs +++ b/frontend/src/uxbox/worker/selection.cljs @@ -44,11 +44,18 @@ nil)) (defmethod impl/handler :selection/query - [{:keys [page-id rect] :as message}] + [{:keys [page-id rect frame-id] :as message}] (when-let [index (get @state page-id)] (let [result (-> (qdt/search index (clj->js rect)) (es6-iterator-seq)) - matches? #(geom/overlaps? % rect)] + matches? (fn [shape] + (and + ;; When not frame-id is passed, we filter the frames + (or (and (not frame-id) (not= :frame (:type shape))) + ;; If we pass a frame-id only get the area for shapes inside that frame + (= frame-id (:frame-id shape))) + (geom/overlaps? shape rect)))] + (into #{} (comp (map #(unchecked-get % "data")) (filter matches?) (map :id)) @@ -56,7 +63,7 @@ (defn- create-index [objects] - (let [shapes (->> (cp/select-toplevel-shapes objects) + (let [shapes (->> (cp/select-toplevel-shapes objects {:include-frames? true}) (map #(merge % (select-keys % [:x :y :width :height])))) bounds (geom/shapes->rect-shape shapes) bounds #js {:x (:x bounds)