From 4b8334fe1c15746f5d8757bfac8f462cfad1d9e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Thu, 11 Feb 2021 10:58:58 +0100 Subject: [PATCH] :bug: Fix ordering when restoring deleted shapes in sync --- CHANGES.md | 1 + .../data/workspace/libraries_helpers.cljs | 26 ++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1e1204380..9f7848986 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -27,6 +27,7 @@ - Fix logo icon in viewer should go to dashboard - Fix text alignment in preview [#594](https://github.com/penpot/penpot/issues/594) - Fix problem when pasting URL's copied from the browser url bar +- Fix ordering when restoring deleted shapes in sync [Taiga #1163](https://tree.taiga.io/project/penpot/issue/1163) ### Community contributions by (Thank you! :heart:) diff --git a/frontend/src/app/main/data/workspace/libraries_helpers.cljs b/frontend/src/app/main/data/workspace/libraries_helpers.cljs index d6f8bff60..44fd6c31f 100644 --- a/frontend/src/app/main/data/workspace/libraries_helpers.cljs +++ b/frontend/src/app/main/data/workspace/libraries_helpers.cljs @@ -626,6 +626,8 @@ (contains? (:touched shape-inst) :shapes-group)) (add-shape-to-instance child-master + (d/index-of children-master + child-master) component container root-inst @@ -649,11 +651,11 @@ reset? initial-root?))) - moved (fn [shape-inst shape-master] + moved (fn [child-inst child-master] (move-shape - shape-inst - (d/index-of children-inst shape-inst) - (d/index-of children-master shape-master) + child-inst + (d/index-of children-inst child-inst) + (d/index-of children-master child-master) container omit-touched?)) @@ -742,6 +744,8 @@ only-inst (fn [child-inst] (add-shape-to-master child-inst + (d/index-of children-inst + child-inst) component container root-inst @@ -768,11 +772,11 @@ root-master) initial-root?))) - moved (fn [shape-inst shape-master] + moved (fn [child-inst child-master] (move-shape - shape-master - (d/index-of children-master shape-master) - (d/index-of children-inst shape-inst) + child-master + (d/index-of children-master child-master) + (d/index-of children-inst child-inst) component-container false)) @@ -863,7 +867,7 @@ (concat-changes (moved-cb child-inst' child-master)))))))))))) (defn- add-shape-to-instance - [component-shape component container root-instance root-master omit-touched? set-remote-synced?] + [component-shape index component container root-instance root-master omit-touched? set-remote-synced?] (log/info :msg (str "ADD [P] " (:name component-shape))) (let [component-parent-shape (cp/get-shape component (:parent-id component-shape)) parent-shape (d/seek #(cp/is-master-of component-parent-shape %) @@ -904,6 +908,7 @@ (as-> {:type :add-obj :id (:id shape') :parent-id (:parent-id shape') + :index index :ignore-touched true :obj shape'} $ (cond-> $ @@ -929,7 +934,7 @@ [rchanges uchanges]))) (defn- add-shape-to-master - [shape component page root-instance root-master] + [shape index component page root-instance root-master] (log/info :msg (str "ADD [C] " (:name shape))) (let [parent-shape (cp/get-shape page (:parent-id shape)) component-parent-shape (d/seek #(cp/is-master-of % parent-shape) @@ -963,6 +968,7 @@ :id (:id shape') :component-id (:id component) :parent-id (:parent-id shape') + :index index :ignore-touched true :obj shape'}) new-shapes)