🐛 Give a bool created in a grid the cell of the shape it replaces

Creating a bool from shapes in a grid board left the bool without a grid
cell: the JVM layout read the cell of a missing row and threw, and the
frontend laid the bool out in no cell. A group takes the cell of its
last shape and reassigns its grid's cells; the bool now takes the cell
of the shape whose place it takes in the parent, and the grid parents of
its shapes reassign their cells.

Test: a-bool-in-a-grid-takes-the-cell-of-its-last-shape (found by the new
shape structure gate).
Focused: groups-test, 6 tests, 0 failures; the full common suite runs at
the end of this series.

Benchmark (scripts/bench-components, ms, lower 2.5% quantile), measured
with the other production changes of this series in the tree; none of
them is on a measured path:
|                             :world | :baseline |    :now |   :mean | :ratio |
|------------------------------------+-----------+---------+---------+--------|
|  deepest-edit-through-three-levels |    35.215 |  22.167 |  22.682 |   0.63 |
| edit-through-a-chain-of-dependents |    68.931 |  43.218 |  44.696 |   0.63 |
|         library-update-into-copies |    83.083 |  47.824 |  50.506 |   0.58 |
|        main-edit-among-many-shapes |     4.837 |   2.216 |    2.34 |   0.46 |
|           main-edit-into-10-copies |      1.79 |   1.067 |   1.133 |    0.6 |
|          main-edit-into-100-copies |    15.415 |  10.604 |  10.813 |   0.69 |
|         main-edit-into-1000-copies |   153.086 | 106.085 | 108.631 |   0.69 |
|         variant-switch-into-copies |    32.052 |  22.556 |  23.137 |    0.7 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-12 01:34:11 +01:00
parent a9357626ac
commit 61b52860e5
2 changed files with 43 additions and 2 deletions

View File

@ -99,10 +99,30 @@
(create-bool-shape force-shape-id type name (reverse shapes) objects)
shape-id
(get shape :id)]
(get shape :id)
;; the bool takes the grid cell of the shape whose place it takes
head-id
(:id (if (= type :difference) (last shapes) (first shapes)))
parent-id
(:parent-id shape)
target-cell
(when (ctl/grid-layout? objects parent-id)
(ctl/get-cell-by-shape-id (get objects parent-id) head-id))
grid-parents
(into #{} (comp (map :parent-id) (filter (partial ctl/grid-layout? objects))) shapes)]
[shape
(-> (pcb/empty-changes it page-id)
(pcb/with-objects objects)
(pcb/add-object shape {:index (inc index)})
(pcb/update-shapes (map :id shapes) ctl/remove-layout-item-data)
(pcb/change-parent shape-id shapes))]))))
(pcb/change-parent shape-id shapes)
(cond-> target-cell
(pcb/update-shapes
[parent-id]
(fn [parent]
(assoc-in parent [:layout-grid-cells (:id target-cell) :shapes] [shape-id]))))
(pcb/update-shapes grid-parents ctl/assign-cells {:with-objects? true}))]))))

View File

@ -13,6 +13,7 @@
[app.common.test-helpers.files :as thf]
[app.common.test-helpers.ids-map :as thi]
[app.common.test-helpers.shapes :as ths]
[app.common.types.shape.layout :as ctl]
[app.common.uuid :as uuid]
[clojure.test :as t]))
@ -79,3 +80,23 @@
(t/is (= :bool (:type (get (objects file) (:id shape)))))
(t/is (= #{(thi/id :rect-a) (thi/id :rect-b)} (set (:shapes (get (objects file) (:id shape))))))
(t/is (nil? (clb/generate-create-bool nil (:id page) (:objects page) [(thi/id :board)] :union nil)))))
(t/deftest a-bool-in-a-grid-takes-the-cell-of-its-last-shape
(let [file (-> (thf/sample-file :file1)
(tho/add-frame :grid :layout :grid
:layout-grid-rows [{:type :flex :value 1}]
:layout-grid-columns [{:type :flex :value 1} {:type :flex :value 1}])
(ths/add-sample-shape :rect-a :parent-label :grid)
(ths/add-sample-shape :rect-b :parent-label :grid)
(ths/update-shape :grid :layout-grid-cells {})
(as-> file (let [page (thf/current-page file)]
(ths/update-shape file :grid :layout-grid-cells
(:layout-grid-cells
(ctl/assign-cells (get (:objects page) (thi/id :grid))
(:objects page)))))))
page (thf/current-page file)
ids (map thi/id [:rect-a :rect-b])
[shape changes] (clb/generate-create-bool nil (:id page) (:objects page) ids :union nil)
file (thf/apply-changes file changes)
grid (get (objects file) (thi/id :grid))]
(t/is (some #(= [(:id shape)] (:shapes %)) (vals (:layout-grid-cells grid))))))