mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Carry no grid cells a switched copy already shows
A switch between variants with identical grids carried the copy's cells and marked them as an override whenever its cells were touched along its reference chain, also when they were the cells the new copy shows. When both variant mains hold the same cell override, a copy that showed it without one of its own ended with a redundant cell override after the switch. The cells now carry only when they differ from the new copy's, as every other attribute does; the component model predicts the same. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 19.449 | 0.55 | | edit-through-a-chain-of-dependents | 68.931 | 40.962 | 0.59 | | library-update-into-copies | 83.083 | 45.075 | 0.54 | | main-edit-among-many-shapes | 4.837 | 1.959 | 0.41 | | main-edit-into-10-copies | 1.790 | 0.933 | 0.52 | | main-edit-into-100-copies | 15.415 | 9.038 | 0.59 | | main-edit-into-1000-copies | 153.086 | 91.626 | 0.60 | | variant-switch-into-copies | 32.052 | 21.183 | 0.66 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
1b0137bde8
commit
85aca392b6
@ -413,8 +413,9 @@
|
||||
"Carry the cell overrides of the switched grid `old` into `new`, its clean
|
||||
copy of the new variant, when the old main `old-ref` and `new` have
|
||||
identical grids: the same tracks and the same cells holding
|
||||
corresponding children. Otherwise the new variant's cells win.
|
||||
`counterpart` gives the child of `new` that relates to a child of `old`."
|
||||
corresponding children, and they differ from the cells `new` shows.
|
||||
Otherwise the new variant's cells win. `counterpart` gives the child of
|
||||
`new` that relates to a child of `old`."
|
||||
[changes old old-ref new old-path new-path counterpart]
|
||||
(let [identical? (and (= (:layout-grid-rows old-ref) (:layout-grid-rows new))
|
||||
(= (:layout-grid-columns old-ref) (:layout-grid-columns new))
|
||||
@ -431,8 +432,12 @@
|
||||
(reduced nil)
|
||||
(assoc cells id (assoc cell :id id :shapes shapes)))))
|
||||
{}
|
||||
(vals (:layout-grid-cells old))))]
|
||||
(if cells
|
||||
(vals (:layout-grid-cells old))))
|
||||
;; cells the new copy already shows are no override
|
||||
shown? (fn [cells]
|
||||
(= (set (map #(dissoc % :id) (vals cells)))
|
||||
(set (map #(dissoc % :id) (vals (:layout-grid-cells new))))))]
|
||||
(if (and cells (not (shown? cells)))
|
||||
(pcb/update-shapes changes [(:id new)]
|
||||
#(-> %
|
||||
(assoc :layout-grid-cells cells)
|
||||
|
||||
@ -1785,6 +1785,13 @@
|
||||
[:variant-property 0 0 0 0] [:switch 1] [:make-variant 13 0 0 0]
|
||||
[:variant-property 0 0 0 0] [:switch 6]]}))))
|
||||
|
||||
(t/deftest switching-a-copy-to-an-identical-grid-it-already-shows-adds-no-override
|
||||
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout :grid :variant-diff false
|
||||
:layout-item-margins false :grid-square false :rich-variants true
|
||||
:layout-children false :grid-empty false :layout-copies true :text true}]
|
||||
:ops [[:grid-cell 1 0 0 0] [:delete 5 0 0 0] [:make-variant 4 0 0 0]
|
||||
[:variant-property 0 0 0 0] [:switch 9]]}))))
|
||||
|
||||
(t/deftest random-variant-compositions
|
||||
(let [coverage (atom {})
|
||||
failure (atom nil)]
|
||||
|
||||
@ -3905,3 +3905,18 @@
|
||||
(t/is (= [1 3] (item-cell file' copy' "Item 3")))
|
||||
(t/is (= [1 1] (item-cell file' copy' "Item 1")))
|
||||
(t/is (not (ctk/touched-group? copy' :layout-grid-cells)))))
|
||||
|
||||
(t/deftest a-switch-between-identical-grids-carries-no-cells-the-new-copy-shows
|
||||
;; the copy's cells are marked as an override but equal its main's, so a
|
||||
;; switch to an identical grid has nothing to carry
|
||||
(let [file (-> (thf/sample-file :file1)
|
||||
(ths/add-sample-shape :v01 :type :frame :is-variant-container true)
|
||||
(add-grid-member :v01 :blue :blue-root "Blue" 2 [[1 1] [1 2] [2 1]])
|
||||
(add-grid-member :v01 :green :green-root "Green" 2 [[1 1] [1 2] [2 1]])
|
||||
(thc/instantiate-component :blue :copy01)
|
||||
(ths/update-shape :copy01 :touched #{:layout-grid-cells}))
|
||||
file' (tho/swap-component-in-shape file :copy01 :green {:new-shape-label :copy02 :keep-touched? true})
|
||||
copy' (ths/get-shape file' :copy02)]
|
||||
(t/is (= [1 1] (item-cell file' copy' "Item 1")))
|
||||
(t/is (= [2 1] (item-cell file' copy' "Item 3")))
|
||||
(t/is (not (ctk/touched-group? copy' :layout-grid-cells)))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user