From b5e53b57d1f8789c2f7165527983b9a7bffdec05 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Fri, 30 Dec 2022 14:39:07 +0100 Subject: [PATCH] :tada: Dynamic alignment only in sight --- CHANGES.md | 1 + frontend/src/app/main/snap.cljs | 8 ++++++-- frontend/src/app/worker/snaps.cljs | 16 ++++++++++------ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 62ca75f71..638f8e631 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ - Better overlays interactions on boards inside boards [Taiga #4386](https://tree.taiga.io/project/penpot/us/4386) - Show board miniature in manual overlay setting [Taiga #4475](https://tree.taiga.io/project/penpot/issue/4475) - Handoff visual improvements [Taiga #3124](https://tree.taiga.io/project/penpot/us/3124) +- Dynamic alignment only in sight [Github 1971](https://github.com/penpot/penpot/issues/1971) ### :bug: Bugs fixed diff --git a/frontend/src/app/main/snap.cljs b/frontend/src/app/main/snap.cljs index b4984e630..3a602ebf7 100644 --- a/frontend/src/app/main/snap.cljs +++ b/frontend/src/app/main/snap.cljs @@ -79,11 +79,13 @@ :else zero))) (defn get-snap-points [page-id frame-id remove-snap? zoom point coord] - (let [value (get point coord)] + (let [value (get point coord) + vbox @refs/vbox] (->> (uw/ask! {:cmd :snaps/range-query :page-id page-id :frame-id frame-id :axis coord + :bounds vbox :ranges [[(- value (/ 0.5 zoom)) (+ value (/ 0.5 zoom))]]}) (rx/take 1) (rx/map (remove-from-snap-points remove-snap?))))) @@ -94,11 +96,13 @@ ranges (->> points (map coord) (mapv #(vector (- % snap-accuracy) - (+ % snap-accuracy))))] + (+ % snap-accuracy)))) + vbox @refs/vbox] (->> (uw/ask! {:cmd :snaps/range-query :page-id page-id :frame-id frame-id :axis coord + :bounds vbox :ranges ranges}) (rx/take 1) (rx/map (remove-from-snap-points remove-snap?)) diff --git a/frontend/src/app/worker/snaps.cljs b/frontend/src/app/worker/snaps.cljs index 9c99779cb..8eeb04d62 100644 --- a/frontend/src/app/worker/snaps.cljs +++ b/frontend/src/app/worker/snaps.cljs @@ -6,6 +6,7 @@ (ns app.worker.snaps (:require + [app.common.geom.shapes.rect :as gpr] [app.util.snap-data :as sd] [app.worker.impl :as impl] [okulary.core :as l])) @@ -24,11 +25,14 @@ nil) (defmethod impl/handler :snaps/range-query - [{:keys [page-id frame-id axis ranges] :as message}] - - (into [] - (comp (mapcat #(sd/query @state page-id frame-id axis %)) - (distinct)) - ranges)) + [{:keys [page-id frame-id axis ranges bounds] :as message}] + (let [match-bounds? + (fn [[_ data]] + (some #(gpr/contains-point? bounds %) (map :pt data)))] + (->> (into [] + (comp (mapcat #(sd/query @state page-id frame-id axis %)) + (distinct)) + ranges) + (filter match-bounds?))))