diff --git a/common/src/app/common/logic/shapes.cljc b/common/src/app/common/logic/shapes.cljc index afb94ee564..c861d74797 100644 --- a/common/src/app/common/logic/shapes.cljc +++ b/common/src/app/common/logic/shapes.cljc @@ -555,6 +555,14 @@ shapes to-index) + ;; A move also removes children from their previous layout. + (pcb/update-shapes (disj all-parents parent-id) + (fn [shape objects] + (if (ctl/grid-layout? shape) + (ctl/assign-cell-positions shape objects) + shape)) + {:ignore-touched true :with-objects? true}) + ;; Remove empty groups (pcb/remove-objects groups-to-delete) diff --git a/common/test/common_tests/logic/move_shapes_test.cljc b/common/test/common_tests/logic/move_shapes_test.cljc index 8fdb32cb51..7619e8abbf 100644 --- a/common/test/common_tests/logic/move_shapes_test.cljc +++ b/common/test/common_tests/logic/move_shapes_test.cljc @@ -21,6 +21,25 @@ (t/use-fixtures :each thi/test-fixture) +(t/deftest moving-a-child-out-of-a-grid-clears-its-old-cell + (let [file (-> (thf/sample-file :file1) + (tho/add-grid-frame :grid :width 200 :height 100) + (tho/add-rect :first :parent-label :grid) + (tho/add-rect :second :parent-label :grid) + (tho/place-in-grid-columns :grid 2 {1 :first 2 :second}) + (tho/add-frame :destination)) + page (thf/current-page file) + changes (cls/generate-relocate (-> (pcb/empty-changes nil (:id page)) + (pcb/with-objects (:objects page)) + (pcb/with-library-data (:data file))) + (thi/id :destination) 0 #{(thi/id :first)}) + moved (thf/apply-changes file changes) + grid (ths/get-shape moved :grid) + members (mapcat :shapes (vals (:layout-grid-cells grid))) + undone (thf/apply-changes moved {:redo-changes (:undo-changes changes)})] + (t/is (= #{(thi/id :second)} (set members))) + (t/is (= (thn/normalize-file file) (thn/normalize-file undone))))) + (t/deftest deleting-a-grid-child-clears-its-cell-and-keeps-undo (let [file (-> (thf/sample-file :file1) (tho/add-grid-frame :grid :width 200 :height 100)