mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Grow a track for a grid copy's new child and keep it at sync
A grid copy that authors its cells and has no free cell for a child its main gains grew a column for it at the first sync. The next sync gave the copy its main's columns again, took the grown column for a shrunk inherited track, and fitted the child back into the inherited tracks, stacking it in another child's cell. When a copy's inherited tracks shrink, its default cells past them (automatic, single, aligned by default) give their children back, which take a free slot or a track the grid grows for them, as when they first came. Cells with something of their own are fitted as before, and the overflow is no longer fitted back into the inherited tracks. The grid model does the same, and the oracle accepts the default tracks a grid grows along its flow past its main's. Tests: a-grid-copy-with-its-own-cells-grows-a-column-for-a-new-child-for-good, a-grid-copy-keeps-an-aligned-cell-its-main-takes-a-column-from, a-grid-copy-keeps-its-aligned-cell-when-its-main-adds-a-row. Grid, sync and golden master tests pass (315); grid programs pass (seed 9004, 300). Benchmark (alone; a first run under load read 1.09 for the variant switch world, which F526 does not reach): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+---------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 23.132 | 28.537 | 0.66 | | edit-through-a-chain-of-dependents | 68.931 | 47.053 | 57.855 | 0.68 | | library-update-into-copies | 83.083 | 55.445 | 64.964 | 0.67 | | main-edit-among-many-shapes | 4.837 | 3.117 | 3.305 | 0.64 | | main-edit-into-10-copies | 1.79 | 1.169 | 1.544 | 0.65 | | main-edit-into-100-copies | 15.415 | 13.442 | 14.626 | 0.87 | | main-edit-into-1000-copies | 153.086 | 119.198 | 141.449 | 0.78 | | variant-switch-into-copies | 32.052 | 25.091 | 29.622 | 0.78 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
65f548e437
commit
73b4e0795b
@ -2298,6 +2298,30 @@
|
||||
(ctsl/create-cells shape [column row 1 1])))
|
||||
shape added)))
|
||||
|
||||
(defn- default-cell?
|
||||
"Whether `cell` has nothing of its own: automatic, single and aligned by
|
||||
default."
|
||||
[cell]
|
||||
(and (= :auto (:position cell))
|
||||
(= 1 (:row-span cell) (:column-span cell))
|
||||
(contains? #{nil :auto} (:align-self cell))
|
||||
(contains? #{nil :auto} (:justify-self cell))))
|
||||
|
||||
(defn- without-default-cells-beyond-tracks
|
||||
"`shape` without its default cells past its tracks: their children take a
|
||||
free slot again, or a track the grid grows for them, as when they first
|
||||
came; the cells with something of their own there are fitted instead."
|
||||
[shape]
|
||||
(let [rows (count (:layout-grid-rows shape))
|
||||
cols (count (:layout-grid-columns shape))]
|
||||
(update shape :layout-grid-cells
|
||||
(fn [cells]
|
||||
(into {}
|
||||
(remove (fn [[_ cell]]
|
||||
(and (default-cell? cell)
|
||||
(or (> (:row cell) rows) (> (:column cell) cols)))))
|
||||
cells)))))
|
||||
|
||||
(defn- assign-inherited-grid-cells
|
||||
[shape before objects]
|
||||
(if-not (or (< (count (:layout-grid-rows shape)) (count (:layout-grid-rows before)))
|
||||
@ -2313,14 +2337,11 @@
|
||||
(and active? (empty? (:layout-grid-columns shape)))
|
||||
(assoc :layout-grid-columns [ctsl/default-track-value]))]
|
||||
(-> target
|
||||
(without-default-cells-beyond-tracks)
|
||||
(ctsl/check-deassigned-cells objects)
|
||||
(ctsl/fit-cells-to-tracks)
|
||||
(ctsl/assign-cells objects)
|
||||
;; New children can exhaust the remaining slots. Fit any overflow
|
||||
;; back into inherited tracks instead of deriving extra tracks.
|
||||
(assoc :layout-grid-rows (:layout-grid-rows target)
|
||||
:layout-grid-columns (:layout-grid-columns target))
|
||||
(ctsl/fit-cells-to-tracks)))))
|
||||
;; a child without a free slot grows a default track to hold it
|
||||
(ctsl/assign-cells objects)))))
|
||||
|
||||
(defn- keep-cell-ids
|
||||
"`shape` with the cells its tracks add, those its main `shape-main` lacks,
|
||||
|
||||
@ -2573,6 +2573,25 @@
|
||||
:layout-copies true :layout-children false}]
|
||||
:ops [[:style 8 29 1] [:nest 6] [:switch 9]]}))))
|
||||
|
||||
(t/deftest a-grid-copy-with-its-own-cells-grows-a-column-for-a-new-child-for-good
|
||||
(t/is (map? (cg/run {:world [2 2 {:variants true :layout :grid :layout-item-margins false :grid-square false
|
||||
:rich-variants true :layout-children false :grid-empty true
|
||||
:layout-copies true :text true}]
|
||||
:ops [[:detach 0] [:grid-cell 0 0 0 1] [:grid-track 4 4 0 9] [:swap 7] [:grid-track 0 3]
|
||||
[:grid-track 7] [:nest 18]]}))))
|
||||
|
||||
(t/deftest a-grid-copy-keeps-an-aligned-cell-its-main-takes-a-column-from
|
||||
(t/is (map? (cg/run {:world [1 1 {:variants false :layout :grid :layout-item-margins false :grid-square false
|
||||
:rich-variants false :layout-children false :grid-empty true
|
||||
:layout-copies true :text false}]
|
||||
:ops [[:grid-cell 4 25] [:grid-track 3] [:grid-track 0 3]]}))))
|
||||
|
||||
(t/deftest a-grid-copy-keeps-its-aligned-cell-when-its-main-adds-a-row
|
||||
(t/is (map? (cg/run {:world [1 0 {:variants false :layout :grid :layout-item-margins false :grid-square true
|
||||
:rich-variants false :layout-children true :grid-empty false
|
||||
:layout-copies false :text false}]
|
||||
:ops [[:grid-cell 0 15 0 1] [:grid-track 0 2]]}))))
|
||||
|
||||
(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}]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user