🐛 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
This commit is contained in:
alonso.torres 2026-10-23 09:06:15 +02:00
parent b86ca2f7fd
commit ed4767ebfd
2 changed files with 20 additions and 3 deletions

View File

@ -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])))

View File

@ -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')))))
(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)))))