From cbe8587db3c11d790dd97c3fb60269bec29991d8 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 16 Mar 2023 15:08:49 +0100 Subject: [PATCH] :bug: Fix problem with z positioning of elements --- CHANGES.md | 1 + common/src/app/common/types/shape_tree.cljc | 42 ++++++++------------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 84b4fd9d6b..3189658d0d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -31,6 +31,7 @@ - Fix problems with touch devices and Wacom tablets [#2216](https://github.com/penpot/penpot/issues/2216) - Fix problem with board titles misplaced [Taiga #4738](https://tree.taiga.io/project/penpot/issue/4738) - Fix problem with alt getting stuck when alt+tab [Taiga #5013](https://tree.taiga.io/project/penpot/issue/5013) +- Fix problem with z positioning of elements [Taiga #5014](https://tree.taiga.io/project/penpot/issue/5014) ### :heart: Community contributions by (Thank you!) - To @ondrejkonec: for contributing to the code with: diff --git a/common/src/app/common/types/shape_tree.cljc b/common/src/app/common/types/shape_tree.cljc index 94eed9c107..5f281a8902 100644 --- a/common/src/app/common/types/shape_tree.cljc +++ b/common/src/app/common/types/shape_tree.cljc @@ -148,17 +148,17 @@ [base idx-a idx-b])) (defn is-shape-over-shape? - [objects base-shape-id over-shape-id] + [objects base-shape-id over-shape-id bottom-frames?] (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 + ;; The base the base shape, so the other item is bellow (if not bottom-frames) (= base base-shape-id) - false + (and bottom-frames? (cph/frame-shape? objects base)) - ;; The base is the testing over, so it's over + ;; The base is the testing over, so it's over (if not bottom-frames) (= base over-shape-id) - true + (or (not bottom-frames?) (not (cph/frame-shape? objects base))) ;; Check which index is lower :else @@ -177,29 +177,19 @@ ([objects ids] (sort-z-index objects ids nil)) - ([objects ids {:keys [bottom-frames?] :as options}] - (letfn [(comp [id-a id-b] - (let [frame-a? (= :frame (dm/get-in objects [id-a :type])) - frame-b? (= :frame (dm/get-in objects [id-b :type]))] - (cond - (= id-a id-b) - 0 + ([objects ids {:keys [bottom-frames?] :as options + :or {bottom-frames? false}}] + (letfn [ + (comp [id-a id-b] + (cond + (= id-a id-b) + 0 - (and (not frame-a?) frame-b?) - (if bottom-frames? -1 1) + (is-shape-over-shape? objects id-a id-b bottom-frames?) + 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 - - :else - 1)))] + :else + -1))] (sort comp ids)))) (defn frame-id-by-position