🐛 Keep the ids of the cells a copy's own grid tracks add

A copy that authors a grid column its main lacks takes its main's cells
fitted to its own tracks. The fitting gave the cell of that column a new
id at every sync, so the copies that follow it took a new id each time,
while one that authors its own cells kept the old one.

The cells a copy's own tracks add keep the ids of its cells in the same
place.

Test: syncing-a-copy-with-its-own-columns-keeps-the-ids-of-their-cells.
Focused grid, sync and golden master tests pass (315 tests).

The benchmark of the previous commit covers this one.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-13 00:20:38 +01:00
parent f8272d89b1
commit 97d0ed02c3
2 changed files with 28 additions and 1 deletions

View File

@ -2292,6 +2292,26 @@
:layout-grid-columns (:layout-grid-columns target))
(ctsl/fit-cells-to-tracks)))))
(defn- keep-cell-ids
"`shape` with the cells its tracks add, those its main `shape-main` lacks,
under the ids of the cells of `shape-copy` in the same place, so each sync
gives them the same ids."
[shape shape-copy shape-main]
(let [place (juxt :row :column :row-span :column-span)
main-ids (set (keys (:layout-grid-cells shape-main)))
previous (into {}
(comp (map val)
(remove #(contains? main-ids (:id %)))
(map (juxt place :id)))
(:layout-grid-cells shape-copy))]
(update shape :layout-grid-cells
(fn [cells]
(into {}
(map (fn [[id cell]]
(let [id (if (contains? main-ids id) id (get previous (place cell) id))]
[id (assoc cell :id id)])))
cells)))))
(defn copy-grid-cells
"The grid copy `shape-copy` with the cells of its main `shape-main`, its
own children in place of the main's, laid out in its own direction: the
@ -2313,7 +2333,8 @@
;; a copy with its own track lists keeps its main's cells within them
(cond-> (or (not= (count (:layout-grid-rows shape-copy)) (count (:layout-grid-rows shape-main)))
(not= (count (:layout-grid-columns shape-copy)) (count (:layout-grid-columns shape-main))))
(ctsl/fit-cells-to-tracks))
(-> (ctsl/fit-cells-to-tracks)
(keep-cell-ids shape-copy shape-main)))
(ctsl/assign-cells objects))))
(defn grid-direction-cells

View File

@ -2502,6 +2502,12 @@
:layout-copies false :layout-children true}]
:ops [[:rotate] [:add-child] [:structure 17] [:update-main]]}))))
(t/deftest syncing-a-copy-with-its-own-columns-keeps-the-ids-of-their-cells
(t/is (map? (cg/run {:world [1 2 {:variants false :layout :grid :layout-item-margins false :grid-square false
:rich-variants false :layout-children true :grid-empty true
:layout-copies true :text false}]
:ops [[:grid-track 3 5 0 2] [:grid-track 0 3] [:grid-cell 3 0 0 1]]}))))
(t/deftest settling-a-bool-in-a-grid-copy-twice-keeps-its-shapes-in-place
(t/is (map? (cg/run {:world [3 0 {:variants true :rich-variants true :text true :layout :grid
:layout-copies true :layout-children true}]