From c62905b9a84f9f0e07287840b2fbd8013c8905f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Wed, 28 Apr 2021 16:24:57 +0200 Subject: [PATCH] :bug: Fix ordering of copy+pasted shapes after rect select --- CHANGES.md | 1 + frontend/src/app/main/ui/workspace/viewport/hooks.cljs | 3 ++- frontend/src/app/worker/selection.cljs | 10 ++++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 515d3505fa..f88f801f5b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -28,6 +28,7 @@ - Fix problem with pan and space [#811](https://github.com/penpot/penpot/issues/811) - Fix issue when parsing exponential numbers in paths - Remove legacy system user and team [#843](https://github.com/penpot/penpot/issues/843) +- Fix ordering of copy pasted objects [Taiga #1618](https://tree.taiga.io/project/penpot/issue/1617) - Fix problems with blending modes [#837](https://github.com/penpot/penpot/issues/837) - Fix problem with zoom an selection rect [#845](https://github.com/penpot/penpot/issues/845) - Fix problem displaying team statistics [#859](https://github.com/penpot/penpot/issues/859) diff --git a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs index 2c0a08f8c4..1fe1c16850 100644 --- a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs @@ -100,7 +100,8 @@ {:cmd :selection/query :page-id page-id :rect rect - :include-frames? true})))) + :include-frames? true + :reverse? true})))) ;; we want the topmost shape to be selected first ;; We use ref so we don't recreate the stream on a change transform-ref (mf/use-ref nil) diff --git a/frontend/src/app/worker/selection.cljs b/frontend/src/app/worker/selection.cljs index dd29d20ccb..2d0ac3a5dd 100644 --- a/frontend/src/app/worker/selection.cljs +++ b/frontend/src/app/worker/selection.cljs @@ -41,8 +41,8 @@ nil)) (defmethod impl/handler :selection/query - [{:keys [page-id rect frame-id include-frames? include-groups? disabled-masks] :or {include-groups? true - disabled-masks #{}} :as message}] + [{:keys [page-id rect frame-id include-frames? include-groups? disabled-masks reverse?] + :or {include-groups? true disabled-masks #{} reverse? false} :as message}] (when-let [index (get @state page-id)] (let [result (-> (qdt/search index (clj->js rect)) (es6-iterator-seq)) @@ -76,11 +76,13 @@ (filter (comp overlaps? :frame)) (filter (comp overlaps-masks? :masks)) (filter overlaps?)) - result)] + result) + + keyfn (if reverse? (comp - :z) :z)] (into (d/ordered-set) (->> matching-shapes - (sort-by (comp - :z)) + (sort-by keyfn) (map :id)))))) (defn create-mask-index