From 3e965c96e7a31f4ca8fe1bdf51785143a60b8845 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Thu, 30 Nov 2023 19:34:59 +0100 Subject: [PATCH] :bug: Fix when changing order on main+flex, the copies are badly updated --- common/src/app/common/files/changes.cljc | 10 +++++----- frontend/src/app/main/data/workspace/libraries.cljs | 8 ++++---- .../src/app/main/data/workspace/libraries_helpers.cljs | 6 ++++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 5816177a0..b5b3c6b44 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -467,7 +467,7 @@ (d/update-in-when data [:components component-id :objects] reg-objects)))) (defmethod process-change :mov-objects - [data {:keys [parent-id shapes index page-id component-id ignore-touched after-shape component-swap]}] + [data {:keys [parent-id shapes index page-id component-id ignore-touched after-shape component-swap syncing]}] (letfn [(calculate-invalid-targets [objects shape-id] (let [reduce-fn #(into %1 (calculate-invalid-targets objects %2))] (->> (get-in objects [shape-id :shapes]) @@ -475,15 +475,15 @@ ;; Avoid placing a shape as a direct or indirect child of itself, ;; or inside its main component if it's in a copy, - ;; or inside a copy + ;; or inside a copy, or from a copy (is-valid-move? [objects shape-id] (let [invalid-targets (calculate-invalid-targets objects shape-id) - shape (get objects shape-id) - _ (prn "is-valid-move?")] + shape (get objects shape-id)] (and shape (not (invalid-targets parent-id)) (not (cfh/components-nesting-loop? objects shape-id parent-id)) - (or component-swap + (or component-swap ;; On a component swap it's allowed to change the structure of a copy + syncing ;; If we are syncing the changes of a main component, it's allowed to change the structure of a copy (and (not (ctk/in-component-copy? (get objects (:parent-id shape)))) ;; We don't want to change the structure of component copies (not (ctk/in-component-copy? (get objects parent-id)))))))) ;; We need to check the origin and target frames diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 2f1879180..adce4bd8d 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -946,16 +946,16 @@ changes (pcb/concat-changes library-changes file-changes) - find-shape (fn [data] - (for [page-id [(:page-id data)] - id (:shapes data)] + extract-shapes (fn [change] + (for [page-id [(:page-id change)] + id (:shapes change)] (-> (get-in state [:workspace-data :pages-index page-id :objects id]) (assoc :page-id page-id)))) updated-copies (->> changes :redo-changes (filter #(= (:type %) :reg-objects)) - (mapcat find-shape) + (mapcat extract-shapes) (filter ctk/instance-head?) distinct)] diff --git a/frontend/src/app/main/data/workspace/libraries_helpers.cljs b/frontend/src/app/main/data/workspace/libraries_helpers.cljs index b22860bf3..cfaaaa65d 100644 --- a/frontend/src/app/main/data/workspace/libraries_helpers.cljs +++ b/frontend/src/app/main/data/workspace/libraries_helpers.cljs @@ -1141,14 +1141,16 @@ :parent-id (:parent-id shape) :shapes [(:id shape)] :index index-after - :ignore-touched true})) + :ignore-touched true + :syncing true})) (update :undo-changes conj (make-change container {:type :mov-objects :parent-id (:parent-id shape) :shapes [(:id shape)] :index index-before - :ignore-touched true})))] + :ignore-touched true + :syncing true})))] (if (and (cfh/touched-group? parent :shapes-group) omit-touched?) changes