From ed4767ebfdf4b06e41812d4da0ba9c8611e0253a Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 23 Oct 2026 09:06:15 +0200 Subject: [PATCH] :bug: Assign grid cells when moving shapes from the layers panel Relocate assigned grid cells only when the caller named a target cell. A layers-panel move left the new child unassigned in the main, while sync assigned it in copies. Assign all unplaced children after either route. The regression failed with an empty second cell before the fix. It now places the moved shape there and checks exact undo restoration. Existing move tests and common/frontend lint pass. Sync benchmark ratios against the 1e baseline (lower quantile): main 10/100/1000 copies 0.53/0.58/0.59; three levels 0.52; chain 0.54; library 0.67; many shapes 0.65; variant switch 0.68. No regression flags. AI-assisted-by: GPT-6 --- common/src/app/common/logic/shapes.cljc | 4 ++-- .../common_tests/logic/move_shapes_test.cljc | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/common/src/app/common/logic/shapes.cljc b/common/src/app/common/logic/shapes.cljc index 121dd4fa22..a98977de5d 100644 --- a/common/src/app/common/logic/shapes.cljc +++ b/common/src/app/common/logic/shapes.cljc @@ -593,8 +593,8 @@ ;; Assign the cell when pushing into a specific grid cell (cond-> (some? cell) (-> (ctl/free-cell-shapes ids) - (ctl/push-into-cell ids row column) - (ctl/assign-cells objects))) + (ctl/push-into-cell ids row column))) + (ctl/assign-cells objects) (ctl/assign-cell-positions objects)))) {:with-objects? true}) (pcb/reorder-grid-children [parent-id]))) diff --git a/common/test/common_tests/logic/move_shapes_test.cljc b/common/test/common_tests/logic/move_shapes_test.cljc index 98bf21f6f7..57f176dc7e 100644 --- a/common/test/common_tests/logic/move_shapes_test.cljc +++ b/common/test/common_tests/logic/move_shapes_test.cljc @@ -11,6 +11,7 @@ [app.common.test-helpers.compositions :as tho] [app.common.test-helpers.files :as thf] [app.common.test-helpers.ids-map :as thi] + [app.common.test-helpers.normalize :as thn] [app.common.test-helpers.shapes :as ths] [app.common.test-helpers.tokens :as tht] [app.common.types.tokens-lib :as ctob] @@ -216,4 +217,20 @@ (t/is (nil? (:layout-item-max-w circle'))) (t/is (nil? (:layout-item-min-w circle'))) (t/is (nil? (:layout-item-absolute circle'))) - (t/is (nil? (:layout-item-z-index circle'))))) \ No newline at end of file + (t/is (nil? (:layout-item-z-index circle'))))) +(t/deftest moving-a-shape-into-a-grid-without-a-target-cell-assigns-it + (let [file (-> (thf/sample-file :file1) + (tho/add-grid-frame :grid :width 200 :height 100) + (tho/add-rect :existing {:parent-label :grid}) + (tho/place-in-grid-columns :grid 2 {1 :existing}) + (tho/add-rect :moving)) + page (thf/current-page file) + changes (-> (pcb/empty-changes nil (:id page)) + (pcb/with-objects (:objects page)) + (cls/generate-relocate (thi/id :grid) 1 #{(thi/id :moving)})) + moved (thf/apply-changes file changes) + grid (ths/get-shape moved :grid) + cells (sort-by :column (vals (:layout-grid-cells grid))) + undone (thf/apply-changes moved {:redo-changes (:undo-changes changes)})] + (t/is (= [[(thi/id :existing)] [(thi/id :moving)]] (mapv :shapes cells))) + (t/is (= (thn/normalize-file file) (thn/normalize-file undone)))))