0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 17:00:36 -05:00

Merge pull request #3165 from penpot/hiru-board-selection

 Give frames that are components more priority on selection
This commit is contained in:
Pablo Alba 2023-04-25 21:31:01 +02:00 committed by GitHub
commit f14641396f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 15 deletions

View file

@ -179,34 +179,34 @@
parents-a (cons id-a parents-a) parents-a (cons id-a parents-a)
parents-b (into #{id-b} parents-b) parents-b (into #{id-b} parents-b)
;; Search for the common frame in order ;; Search for the common parent (frame or group) in order
base (or (d/seek parents-b parents-a) uuid/zero) base-id (or (d/seek parents-b parents-a) uuid/zero)
idx-a (get parents-a-index base) idx-a (get parents-a-index base-id)
idx-b (get parents-b-index base)] idx-b (get parents-b-index base-id)]
[base idx-a idx-b])) [base-id idx-a idx-b]))
(defn is-shape-over-shape? (defn is-shape-over-shape?
[objects base-shape-id over-shape-id bottom-frames?] [objects base-shape-id over-shape-id bottom-frames?]
(let [[base index-a index-b] (get-base objects base-shape-id over-shape-id)] (let [[base-id index-a index-b] (get-base objects base-shape-id over-shape-id)]
(cond (cond
;; The base the base shape, so the other item is bellow (if not bottom-frames) ;; The base the base shape, so the other item is below (if not bottom-frames)
(= base base-shape-id) (= base-id base-shape-id)
(and bottom-frames? (cph/frame-shape? objects base)) (and bottom-frames? (cph/frame-shape? objects base-id))
;; The base is the testing over, so it's over (if not bottom-frames) ;; The base is the testing over, so it's over (if not bottom-frames)
(= base over-shape-id) (= base-id over-shape-id)
(or (not bottom-frames?) (not (cph/frame-shape? objects base))) (or (not bottom-frames?) (not (cph/frame-shape? objects base-id)))
;; Check which index is lower ;; Check which index is lower
:else :else
;; If the base is a layout we should check if the z-index property is set ;; If the base is a layout we should check if the z-index property is set
(let [[z-index-a z-index-b] (let [[z-index-a z-index-b]
(if (ctl/any-layout? objects base) (if (ctl/any-layout? objects base-id)
[(ctl/layout-z-index objects (dm/get-in objects [base :shapes index-a])) [(ctl/layout-z-index objects (dm/get-in objects [base-id :shapes index-a]))
(ctl/layout-z-index objects (dm/get-in objects [base :shapes index-b]))] (ctl/layout-z-index objects (dm/get-in objects [base-id :shapes index-b]))]
[0 0])] [0 0])]
(if (= z-index-a z-index-b) (if (= z-index-a z-index-b)

View file

@ -11,6 +11,7 @@
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
[app.common.types.component :as ctk]
[app.common.types.shape-tree :as ctt] [app.common.types.shape-tree :as ctt]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.data.shortcuts :as dsc] [app.main.data.shortcuts :as dsc]
@ -221,7 +222,10 @@
root-frame-with-data? root-frame-with-data?
#(as-> (get objects %) obj #(as-> (get objects %) obj
(and (cph/root-frame? obj) (d/not-empty? (:shapes obj)))) (and (cph/root-frame? obj)
(d/not-empty? (:shapes obj))
(not (ctk/instance-root? obj))
(not (ctk/main-instance? obj))))
;; Set with the elements to remove from the hover list ;; Set with the elements to remove from the hover list
remove-id-xf remove-id-xf