From f3f611848cf313c912aa7638ecf94e953e98aa76 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 7 Mar 2023 16:58:35 +0100 Subject: [PATCH] :bug: Improve deeps selection of nested arboards --- CHANGES.md | 1 + common/src/app/common/pages/helpers.cljc | 8 +++++--- common/src/app/common/types/shape_tree.cljc | 20 +++++++++++-------- .../app/main/ui/workspace/viewport/hooks.cljs | 11 +++++++++- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cc3aab50e..7f7118dca 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,6 +22,7 @@ - Fix problem when undoing multiple selected colors [Taiga #4920](https://tree.taiga.io/project/penpot/issue/4920) - Allow selection of empty board by partial rect [Taiga #4806](https://tree.taiga.io/project/penpot/issue/4806) - Improve behavior for undo on text edition [Taiga #4693](https://tree.taiga.io/project/penpot/issue/4693) +- Improve deeps selection of nested arboards [Taiga #4913](https://tree.taiga.io/project/penpot/issue/4913) ### :arrow_up: Deps updates diff --git a/common/src/app/common/pages/helpers.cljc b/common/src/app/common/pages/helpers.cljc index 76062cee4..a6ad3bfea 100644 --- a/common/src/app/common/pages/helpers.cljc +++ b/common/src/app/common/pages/helpers.cljc @@ -24,9 +24,11 @@ (and (= type :frame) (= id uuid/zero))) (defn root-frame? - [{:keys [frame-id type]}] - (and (= type :frame) - (= frame-id uuid/zero))) + ([objects id] + (root-frame? (get objects id))) + ([{:keys [frame-id type]}] + (and (= type :frame) + (= frame-id uuid/zero)))) (defn frame-shape? ([objects id] diff --git a/common/src/app/common/types/shape_tree.cljc b/common/src/app/common/types/shape_tree.cljc index 3997cd3b3..94eed9c10 100644 --- a/common/src/app/common/types/shape_tree.cljc +++ b/common/src/app/common/types/shape_tree.cljc @@ -179,18 +179,22 @@ ([objects ids {:keys [bottom-frames?] :as options}] (letfn [(comp [id-a id-b] - (let [type-a (dm/get-in objects [id-a :type]) - type-b (dm/get-in objects [id-b :type])] + (let [frame-a? (= :frame (dm/get-in objects [id-a :type])) + frame-b? (= :frame (dm/get-in objects [id-b :type]))] (cond - (and (not= :frame type-a) (= :frame type-b)) - (if bottom-frames? -1 1) - - (and (= :frame type-a) (not= :frame type-b)) - (if bottom-frames? 1 -1) - (= id-a id-b) 0 + (and (not frame-a?) frame-b?) + (if bottom-frames? -1 1) + + (and frame-a? (not frame-b?)) + (if bottom-frames? 1 -1) + + ;; When comparing frames we invert the order if the flag `bottom-frames?` is on + (and frame-a? frame-b? bottom-frames?) + (if (is-shape-over-shape? objects id-b id-a) 1 -1) + (is-shape-over-shape? objects id-b id-a) -1 diff --git a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs index ab0d5aa64..4ececf323 100644 --- a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs @@ -7,6 +7,7 @@ (ns app.main.ui.workspace.viewport.hooks (:require [app.common.data :as d] + [app.common.data.macros :as dm] [app.common.geom.shapes :as gsh] [app.common.pages :as cp] [app.common.pages.helpers :as cph] @@ -169,7 +170,8 @@ ;; but the mouse has not been moved from its position. (->> mod-str (rx/observe-on :async) - (rx/map #(deref last-point-ref))) + (rx/map #(deref last-point-ref)) + (rx/merge-map query-point)) (->> move-stream (rx/tap #(reset! last-point-ref %)) @@ -241,10 +243,17 @@ remove-id? (into selected-with-parents remove-id-xf ids) + no-fill-nested-frames? + (fn [id] + (and (cph/frame-shape? objects id) + (not (cph/root-frame? objects id)) + (empty? (dm/get-in objects [id :fills])))) + hover-shape (->> ids (remove remove-id?) (remove (partial cph/hidden-parent? objects)) + (remove no-fill-nested-frames?) (filter #(or (empty? focus) (cp/is-in-focus? objects focus %))) (first) (get objects))]