0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 08:50:57 -05:00

🐛 Fix problem with selection on nested boards

This commit is contained in:
alonso.torres 2023-01-31 13:59:14 +01:00
parent 6be83fc6d6
commit 70fa169d0d
2 changed files with 28 additions and 23 deletions

View file

@ -109,6 +109,20 @@
(recur (conj result parent-id) parent-id)
result))))
(defn get-parent-ids-with-index
"Returns a tuple with the list of parents and a map with the position within each parent"
[objects shape-id]
(loop [parent-list []
parent-indices {}
current shape-id]
(let [parent-id (dm/get-in objects [current :parent-id])
parent (get objects parent-id)]
(if (and (some? parent) (not= parent-id current))
(let [parent-list (conj parent-list parent-id)
parent-indices (assoc parent-indices parent-id (d/index-of (:shapes parent) current))]
(recur parent-list parent-indices parent-id))
[parent-list parent-indices]))))
(defn get-siblings-ids
[objects id]
(let [parent (get-parent objects id)]

View file

@ -132,43 +132,34 @@
(defn get-base
[objects id-a id-b]
(let [parents-a (reverse (cons id-a (cph/get-parent-ids objects id-a)))
parents-b (reverse (cons id-b (cph/get-parent-ids objects id-b)))
(let [[parents-a parents-a-index] (cph/get-parent-ids-with-index objects id-a)
[parents-b parents-b-index] (cph/get-parent-ids-with-index objects id-b)
[base base-child-a base-child-b]
(loop [parents-a (rest parents-a)
parents-b (rest parents-b)
base uuid/zero]
(cond
(not= (first parents-a) (first parents-b))
[base (first parents-a) (first parents-b)]
parents-a (cons id-a parents-a)
parents-b (into #{id-b} parents-b)
(or (empty? parents-a) (empty? parents-b))
[uuid/zero (first parents-a) (first parents-b)]
;; Search for the common frame in order
base (or (d/seek parents-b parents-a) uuid/zero)
:else
(recur (rest parents-a) (rest parents-b) (first parents-a))))
idx-a (get parents-a-index base)
idx-b (get parents-b-index base)]
index-base-a (when base-child-a (cph/get-position-on-parent objects base-child-a))
index-base-b (when base-child-b (cph/get-position-on-parent objects base-child-b))]
[base index-base-a index-base-b]))
[base idx-a idx-b]))
(defn is-shape-over-shape?
[objects base-shape-id over-shape-id]
(let [[base index-a index-b] (get-base objects base-shape-id over-shape-id)]
(cond
;; The base the base shape, so the other item is bellow
(= base base-shape-id)
(let [object (get objects base-shape-id)]
(or (cph/frame-shape? object)
(cph/root-frame? object)))
false
;; The base is the testing over, so it's over
(= base over-shape-id)
(let [object (get objects over-shape-id)]
(or (not (cph/frame-shape? object))
(not (cph/root-frame? object))))
true
;; Check which index is lower
:else
(< index-a index-b))))