From d654a4faedc2917fb3162f2e469e3c8792167014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Tue, 13 Feb 2024 14:43:30 +0100 Subject: [PATCH] :bug: Avoid setting touched in parent when swapping components --- .../src/app/common/files/changes_builder.cljc | 13 ++++++++----- .../app/main/data/workspace/libraries.cljs | 3 ++- .../src/app/main/data/workspace/shapes.cljs | 19 +++++++++---------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index f5d1cf201..f868cbd2a 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -326,7 +326,9 @@ (some? index) (assoc :index index) (:component-swap options) - (assoc :component-swap true)) + (assoc :component-swap true) + (:ignore-touched options) + (assoc :ignore-touched true)) mk-undo-change (fn [undo-changes shape] @@ -450,10 +452,11 @@ add-redo-change (fn [change-set id] (conj change-set - {:type :del-obj - :page-id page-id - :ignore-touched ignore-touched - :id id})) + (cond-> {:type :del-obj + :page-id page-id + :id id} + ignore-touched + (assoc :ignore-touched true)))) add-undo-change-shape (fn [change-set id] diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 1fab0ddcd..5edcafbe0 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -898,7 +898,8 @@ (pcb/update-shapes [(:id new-shape)] #(d/patch-object % keep-props-values)) ;; We need to set the same index as the original shape - (pcb/change-parent (:parent-id shape) [new-shape] index {:component-swap true}))] + (pcb/change-parent (:parent-id shape) [new-shape] index {:component-swap true + :ignore-touched true}))] ;; First delete so we don't break the grid layout cells (rx/of (dch/commit-changes changes) diff --git a/frontend/src/app/main/data/workspace/shapes.cljs b/frontend/src/app/main/data/workspace/shapes.cljs index 99e13369a..805669e4d 100644 --- a/frontend/src/app/main/data/workspace/shapes.cljs +++ b/frontend/src/app/main/data/workspace/shapes.cljs @@ -142,17 +142,17 @@ (rx/concat (rx/of (dwu/start-undo-transaction undo-id) (update-shape-flags ids-to-hide {:hidden true})) - (real-delete-shapes file page objects ids-to-delete it components-v2) + (real-delete-shapes file page objects ids-to-delete it components-v2 (:component-swap options)) (rx/of (dwu/commit-undo-transaction undo-id)))))))) (defn- real-delete-shapes-changes - ([file page objects ids it components-v2] + ([file page objects ids it components-v2 ignore-touched] (let [changes (-> (pcb/empty-changes it (:id page)) (pcb/with-page page) (pcb/with-objects objects) (pcb/with-library-data file))] - (real-delete-shapes-changes changes file page objects ids it components-v2))) - ([changes file page objects ids _it components-v2] + (real-delete-shapes-changes changes file page objects ids it components-v2 ignore-touched))) + ([changes file page objects ids _it components-v2 ignore-touched] (let [lookup (d/getf objects) groups-to-unmask (reduce (fn [group-ids id] @@ -252,7 +252,7 @@ changes (-> changes (pcb/remove-objects all-children {:ignore-touched true}) - (pcb/remove-objects ids) + (pcb/remove-objects ids {:ignore-touched ignore-touched}) (pcb/remove-objects empty-parents) (pcb/resize-parents all-parents) (pcb/update-shapes groups-to-unmask @@ -274,13 +274,13 @@ (defn delete-shapes-changes - [changes file page objects ids it components-v2] - (let [[changes _all-parents] (real-delete-shapes-changes changes file page objects ids it components-v2)] + [changes file page objects ids it components-v2 ignore-touched] + (let [[changes _all-parents] (real-delete-shapes-changes changes file page objects ids it components-v2 ignore-touched)] changes)) (defn- real-delete-shapes - [file page objects ids it components-v2] - (let [[changes all-parents] (real-delete-shapes-changes file page objects ids it components-v2) + [file page objects ids it components-v2 ignore-touched] + (let [[changes all-parents] (real-delete-shapes-changes file page objects ids it components-v2 ignore-touched) undo-id (js/Symbol)] (rx/of (dwu/start-undo-transaction undo-id) (dc/detach-comment-thread ids) @@ -288,7 +288,6 @@ (ptk/data-event :layout/update all-parents) (dwu/commit-undo-transaction undo-id)))) - (defn create-and-add-shape [type frame-x frame-y {:keys [width height] :as attrs}] (ptk/reify ::create-and-add-shape