mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 23:49:45 -05:00
🐛 Fixes some issues with dynamic alignment
This commit is contained in:
parent
69f0f16085
commit
2ac8a32986
3 changed files with 24 additions and 8 deletions
|
@ -150,6 +150,7 @@
|
||||||
(defn select-shapes-area [page-id shapes objects area-selrect]
|
(defn select-shapes-area [page-id shapes objects area-selrect]
|
||||||
(->> (uw/ask! {:cmd :selection/query
|
(->> (uw/ask! {:cmd :selection/query
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
|
:frame-id (->> shapes first :frame-id)
|
||||||
:rect area-selrect})
|
:rect area-selrect})
|
||||||
(rx/map #(set/difference % (into #{} (map :id shapes))))
|
(rx/map #(set/difference % (into #{} (map :id shapes))))
|
||||||
(rx/map (fn [ids] (map #(get objects %) ids)))))
|
(rx/map (fn [ids] (map #(get objects %) ids)))))
|
||||||
|
|
|
@ -129,6 +129,7 @@
|
||||||
query-side (fn [side]
|
query-side (fn [side]
|
||||||
(->> (uw/ask! {:cmd :selection/query
|
(->> (uw/ask! {:cmd :selection/query
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
|
:frame-id (:id frame)
|
||||||
:rect (gsh/pad-selrec (areas side))})
|
:rect (gsh/pad-selrec (areas side))})
|
||||||
(rx/map #(set/difference % selected))
|
(rx/map #(set/difference % selected))
|
||||||
(rx/map #(->> % (map (partial get @refs/workspace-objects))))))]
|
(rx/map #(->> % (map (partial get @refs/workspace-objects))))))]
|
||||||
|
@ -154,6 +155,12 @@
|
||||||
(map pair->distance+pair)
|
(map pair->distance+pair)
|
||||||
(filter (comp pred? first))))
|
(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
|
;; Left/Top shapes and right/bottom shapes (depends on `coord` parameter
|
||||||
[lt-shapes gt-shapes] @to-measure
|
[lt-shapes gt-shapes] @to-measure
|
||||||
|
|
||||||
|
@ -161,8 +168,9 @@
|
||||||
lt-distances (->> lt-shapes (map distance-to-selrect) (filter pos?) (into #{}))
|
lt-distances (->> lt-shapes (map distance-to-selrect) (filter pos?) (into #{}))
|
||||||
gt-distances (->> gt-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
|
;; 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
|
;; Checks the distances between elements for distances that match the set of distances
|
||||||
distance-coincidences (concat (get-shapes-match show-candidate? lt-shapes)
|
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
|
;; 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
|
;; or are from the selrect and go to a shape on the left and to the right
|
||||||
show-distance? (into #{} (concat
|
show-distance? #(check-in-set % (into #{} (concat
|
||||||
(map first distance-coincidences)
|
(map first distance-coincidences)
|
||||||
(set/intersection lt-distances gt-distances)))
|
(set/intersection lt-distances gt-distances))))
|
||||||
|
|
||||||
;; These are the segments whose distance will be displayed
|
;; These are the segments whose distance will be displayed
|
||||||
|
|
||||||
|
@ -181,7 +189,7 @@
|
||||||
(map second) ;; Retrieves list of [shape,shape] tuples
|
(map second) ;; Retrieves list of [shape,shape] tuples
|
||||||
(map #(mapv :selrect %))) ;; Changes [shape,shape] to [selrec,selrec]
|
(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)
|
selection-segments (->> (concat lt-shapes gt-shapes)
|
||||||
(filter #(show-distance? (distance-to-selrect %)))
|
(filter #(show-distance? (distance-to-selrect %)))
|
||||||
(map #(vector selrect (:selrect %))))
|
(map #(vector selrect (:selrect %))))
|
||||||
|
|
|
@ -44,11 +44,18 @@
|
||||||
nil))
|
nil))
|
||||||
|
|
||||||
(defmethod impl/handler :selection/query
|
(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)]
|
(when-let [index (get @state page-id)]
|
||||||
(let [result (-> (qdt/search index (clj->js rect))
|
(let [result (-> (qdt/search index (clj->js rect))
|
||||||
(es6-iterator-seq))
|
(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"))
|
(into #{} (comp (map #(unchecked-get % "data"))
|
||||||
(filter matches?)
|
(filter matches?)
|
||||||
(map :id))
|
(map :id))
|
||||||
|
@ -56,7 +63,7 @@
|
||||||
|
|
||||||
(defn- create-index
|
(defn- create-index
|
||||||
[objects]
|
[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]))))
|
(map #(merge % (select-keys % [:x :y :width :height]))))
|
||||||
bounds (geom/shapes->rect-shape shapes)
|
bounds (geom/shapes->rect-shape shapes)
|
||||||
bounds #js {:x (:x bounds)
|
bounds #js {:x (:x bounds)
|
||||||
|
|
Loading…
Add table
Reference in a new issue