🐛 Fit a group again when undoing the sync of its attributes

An update main that pushes a turn into a main holding a group turns the
group and its shapes. Its undo restores the shapes first and fits the
group around them while the group still has the turned transform, which
writes the turned bounds into its width and height; the group's own undo
then restores only the attributes the update main changed, so the group
kept the turned size.

The undo of a shape's synced attributes fits the shape itself, after its
own undo, as well as its parents; only groups and bools are fitted.

Test: undoing-an-update-main-that-turns-a-group-gives-the-group-its-size-back.
Focused sync, undo, group and golden master tests pass.

Benchmark (alone, shared with the next two commits):

|                             :world | :baseline |    :now |   :mean | :ratio |
|------------------------------------+-----------+---------+---------+--------|
|  deepest-edit-through-three-levels |    35.215 |   20.59 |  22.349 |   0.58 |
| edit-through-a-chain-of-dependents |    68.931 |  41.197 |   42.87 |    0.6 |
|         library-update-into-copies |    83.083 |  50.286 |  53.679 |   0.61 |
|        main-edit-among-many-shapes |     4.837 |   2.582 |   3.885 |   0.53 |
|           main-edit-into-10-copies |      1.79 |   1.132 |    1.22 |   0.63 |
|          main-edit-into-100-copies |    15.415 |  10.634 |  11.318 |   0.69 |
|         main-edit-into-1000-copies |   153.086 | 100.406 | 125.813 |   0.66 |
|         variant-switch-into-copies |    32.052 |  21.303 |  22.718 |   0.66 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-13 00:20:27 +01:00
parent 47603c4aa9
commit f8272d89b1
2 changed files with 13 additions and 4 deletions

View File

@ -1762,15 +1762,19 @@
(defn add-update-attr-changes
"Add to `changes` the operations of `attr-operations` on `dest-shape`, and
the update of its parents."
the update of its parents. The undo fits the shape itself too, when it is a
group or bool: its children are undone before it, while it keeps the
transform the change gave it."
[changes dest-shape container roperations uoperations]
(let [update-parents {:type :reg-objects
:shapes (cfh/get-parent-ids (:objects container) (:id dest-shape))}]
:shapes (cfh/get-parent-ids (:objects container) (:id dest-shape))}
update-self {:type :reg-objects
:shapes [(:id dest-shape)]}]
(pcb/add-changes changes container
[{:type :mod-obj :id (:id dest-shape) :operations roperations}
update-parents]
;; undone as the shape first, then its parents
[update-parents
;; undone as the shape first, then itself and its parents
[update-self
{:type :mod-obj :id (:id dest-shape) :operations (vec uoperations)}])))

View File

@ -2497,6 +2497,11 @@
:layout-copies false :layout-children false}]
:ops [[:add-child 1] [:structure 2] [:transform 2 2 0 2]]}))))
(t/deftest undoing-an-update-main-that-turns-a-group-gives-the-group-its-size-back
(t/is (map? (cg/run {:world [2 0 {:variants true :rich-variants true :text false :layout :flex
:layout-copies false :layout-children true}]
:ops [[:rotate] [:add-child] [:structure 17] [:update-main]]}))))
(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}]