diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index d5c8f112f5..f7ac1c0561 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -1317,7 +1317,7 @@ (defn- update-grid-copy-attrs "Synchronizes the `layout-grid-cells` property from the main shape to the copies" - [changes shape-copy-id shape-main library component omit-touched?] + [changes shape-copy-id shape-main _library _component omit-touched?] (-> changes (pcb/apply-changes-local) (pcb/update-shapes @@ -1329,8 +1329,10 @@ (map #(get objects %)) (keep (fn [copy-shape] - (let [main-shape (ctf/get-ref-shape library component copy-shape)] - [(:id main-shape) (:id copy-shape)])))) + ;; Paired children refer to this near main, which can + ;; belong to another component when resetting nested copies. + (when-let [ref (:shape-ref copy-shape)] + [ref (:id copy-shape)])))) (:shapes shape-copy)) remove-orphan-cells diff --git a/common/test/common_tests/logic/comp_reset_test.cljc b/common/test/common_tests/logic/comp_reset_test.cljc index 0e6cce05ff..c941bc5048 100644 --- a/common/test/common_tests/logic/comp_reset_test.cljc +++ b/common/test/common_tests/logic/comp_reset_test.cljc @@ -22,10 +22,33 @@ [app.common.test-helpers.shapes :as ths] [app.common.types.container :as ctn] [app.common.types.modifiers :as ctm] + [app.common.types.shape.layout :as ctl] [clojure.test :as t])) (t/use-fixtures :each thi/test-fixture) +(t/deftest reset-a-nested-grid-keeps-the-near-mains-manual-cell + (let [file (-> (thf/sample-file :file1) + (tho/add-grid-frame :inner-root) + (tho/add-rect :inner-child :parent-label :inner-root) + (tho/place-in-grid-columns :inner-root 2 {1 :inner-child}) + (thc/make-component :inner :inner-root) + (tho/add-frame :outer-root) + (thc/instantiate-component :inner :nested :parent-label :outer-root + :children-labels [:nested-child]) + (thc/make-component :outer :outer-root) + (thc/instantiate-component :outer :copy + :children-labels [:copy-nested :copy-child])) + initial (tm/make-situation file) + moved (-> initial (r/step (n/move-to-cell :nested :nested-child 1 2)) r/settle) + reset (-> moved (r/step (n/reset :copy-nested)) r/settle) + column (fn [s] + (let [head (tm/resolve-shape s :copy-nested)] + (:column (ctl/get-cell-by-shape-id head (first (:shapes head))))))] + (t/is (= 2 (column moved))) + (t/is (= 2 (column reset))) + (t/is (nil? (:touched (tm/resolve-shape reset :copy-nested)))))) + (t/deftest reset-a-nested-copy-through-a-deleted-outer-main (let [initial (setup/nested-component-with-copy) edited (-> initial