mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Give a copy head shown again by sync back its grid cell
A grid drops the cell of a child that is hidden. When a reset or a sync showed a hidden copy head again, its parent grid, outside the copy, kept no cell for it, and the next layout pass failed on the missing cell. Syncing a head now assigns its parent grid's cells again when it takes the head in or out of the grid's flow, as showing or hiding a child in the editor does. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+--------+-------| | deepest-edit-through-three-levels | 35.215 | 17.937 | 0.51 | | edit-through-a-chain-of-dependents | 68.931 | 37.042 | 0.54 | | library-update-into-copies | 83.083 | 43.279 | 0.52 | | main-edit-among-many-shapes | 4.837 | 2.071 | 0.43 | | main-edit-into-10-copies | 1.79 | 0.9 | 0.5 | | main-edit-into-100-copies | 15.415 | 9.059 | 0.59 | | main-edit-into-1000-copies | 153.086 | 89.032 | 0.58 | | variant-switch-into-copies | 32.052 | 19.941 | 0.62 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
c09fb3d26c
commit
91bb316f9d
@ -372,6 +372,24 @@
|
||||
(reduce #(update %1 %2 turn) objects
|
||||
(cfh/get-children-ids-with-self objects (:id shape-main)))))))))
|
||||
|
||||
(defn- reassign-parent-grid-cells
|
||||
"`changes` with the cells of the grid that holds the copy head `id`
|
||||
assigned again when they take the head in or out of the grid's flow, as
|
||||
showing or hiding a child does."
|
||||
[changes container id]
|
||||
(let [before (:objects container)
|
||||
parent-id (:parent-id (get before id))]
|
||||
(if (ctsl/grid-layout? before parent-id)
|
||||
(let [changes (pcb/apply-changes-local changes)
|
||||
after (pcb/get-objects changes)]
|
||||
(if (and (contains? after id)
|
||||
(not= (ctsl/position-absolute? before id) (ctsl/position-absolute? after id)))
|
||||
(-> changes
|
||||
(pcb/update-shapes [parent-id] ctsl/assign-cells {:with-objects? true :ignore-touched true})
|
||||
(pcb/reorder-grid-children [parent-id]))
|
||||
changes))
|
||||
changes)))
|
||||
|
||||
(defn generate-sync-shape-direct
|
||||
"Generate changes to synchronize one shape that is the root of a component
|
||||
instance, and all its children, from the given component."
|
||||
@ -397,17 +415,18 @@
|
||||
library file libraries component)
|
||||
main-container (main-in-parent-orientation main-container shape-main container shape-inst reset?)
|
||||
shape-main (ctn/get-shape main-container (:id shape-main))]
|
||||
(sync-copy-recursive changes
|
||||
{:container container
|
||||
:main-container main-container
|
||||
:component component
|
||||
:library library
|
||||
;; Reset also places new children in the main's frame.
|
||||
:root-inst (cond-> shape-inst reset? (dissoc :touched))
|
||||
:root-main shape-main
|
||||
:reset? reset?}
|
||||
shape-inst
|
||||
shape-main))
|
||||
(-> (sync-copy-recursive changes
|
||||
{:container container
|
||||
:main-container main-container
|
||||
:component component
|
||||
:library library
|
||||
;; Reset also places new children in the main's frame.
|
||||
:root-inst (cond-> shape-inst reset? (dissoc :touched))
|
||||
:root-main shape-main
|
||||
:reset? reset?}
|
||||
shape-inst
|
||||
shape-main)
|
||||
(reassign-parent-grid-cells container shape-id)))
|
||||
|
||||
;; If the component is not found, because the master component has been
|
||||
;; deleted or the library unlinked, do nothing.
|
||||
|
||||
@ -860,3 +860,17 @@
|
||||
child (some #(when (:layout-item-absolute %) %) (vals objects))]
|
||||
(t/is (:shape-ref child))
|
||||
(t/is (contains? (:touched child) :geometry-group))))
|
||||
|
||||
(t/deftest generated-reset-shows-a-hidden-head-back-in-its-grid-cell
|
||||
;; a detached grid holds a nested head its copy hid; the reset shows it
|
||||
;; again, and the resize lays the grid out
|
||||
(let [result (cg/run {:world [2 0 {:text true :text-styles true :layout :grid}]
|
||||
:ops [[:nest 0 0 0 0] [:detach 1 0 0 0] [:style 1 1 1 1]
|
||||
[:edit 1 1 1 :copy-head] [:reset 1] [:resize 1 0 0 0]]})
|
||||
objects (:objects (thf/current-page (tm/file (:situation result))))]
|
||||
(doseq [grid (filter #(= :grid (:layout %)) (vals objects))
|
||||
:let [in-cells (set (mapcat :shapes (vals (:layout-grid-cells grid))))]
|
||||
id (:shapes grid)
|
||||
:let [child (get objects id)]
|
||||
:when (not (or (:hidden child) (:layout-item-absolute child)))]
|
||||
(t/is (contains? in-cells id) (:name child)))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user