mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Restore a group's whole geometry when undoing the sync of it
The undo of a group's synced attributes fitted the group to its children again, after its own undo, so a turned group would not keep the turned size an earlier fit gave it. But fitting a group clears its flip flags, so a flipped group came back unflipped. The undo of a group or bool whose geometry a sync changes restores all of it, its place, size, corners, transform, turn and flips, whatever fits of it ran before. Tests: a-copy-group-whose-main-turns-matches-its-corners-whatever-its-flips, undoing-an-update-main-that-turns-a-group-gives-the-group-its-size-back. Benchmark (alone): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+--------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 20.394 | 21.255 | 0.58 | | edit-through-a-chain-of-dependents | 68.931 | 43.583 | 44.351 | 0.63 | | library-update-into-copies | 83.083 | 51.967 | 52.683 | 0.63 | | main-edit-among-many-shapes | 4.837 | 2.366 | 2.526 | 0.49 | | main-edit-into-10-copies | 1.79 | 1.044 | 1.132 | 0.58 | | main-edit-into-100-copies | 15.415 | 9.805 | 10.146 | 0.64 | | main-edit-into-1000-copies | 153.086 | 98.202 | 101.844 | 0.64 | | variant-switch-into-copies | 32.052 | 21.832 | 22.268 | 0.68 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
fa1edc78bd
commit
8ed42aadac
@ -1769,22 +1769,35 @@
|
||||
(seq applied-tokens)
|
||||
(update-tokens container dest-shape origin-shape applied-tokens)))))
|
||||
|
||||
(def ^:private derived-geometry-attrs
|
||||
"The geometry a group or bool takes from its children."
|
||||
[:x :y :width :height :selrect :points :transform :transform-inverse
|
||||
:rotation :flip-x :flip-y])
|
||||
|
||||
(defn add-update-attr-changes
|
||||
"Add to `changes` the operations of `attr-operations` on `dest-shape`, and
|
||||
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."
|
||||
the update of its parents. The undo of a group or bool whose geometry
|
||||
changes restores all of it: its children are undone before it, and fitting
|
||||
it to them meanwhile, while it keeps the transform the change gave it,
|
||||
rewrites geometry the change did not touch."
|
||||
[changes dest-shape container roperations uoperations]
|
||||
(let [update-parents {:type :reg-objects
|
||||
:shapes (cfh/get-parent-ids (:objects container) (:id dest-shape))}
|
||||
update-self {:type :reg-objects
|
||||
:shapes [(:id dest-shape)]}]
|
||||
undone (into #{} (map :attr) uoperations)
|
||||
uoperations (cond-> (vec uoperations)
|
||||
(and (#{:group :bool} (:type dest-shape))
|
||||
(some (set derived-geometry-attrs) undone))
|
||||
(into (comp (remove undone)
|
||||
(map (fn [attr]
|
||||
{:type :set :attr attr :val (get dest-shape attr)
|
||||
:ignore-touched true})))
|
||||
derived-geometry-attrs))]
|
||||
(pcb/add-changes changes container
|
||||
[{:type :mod-obj :id (:id dest-shape) :operations roperations}
|
||||
update-parents]
|
||||
;; undone as the shape first, then itself and its parents
|
||||
[update-self
|
||||
{:type :mod-obj :id (:id dest-shape) :operations (vec uoperations)}])))
|
||||
;; undone as the shape first, then its parents
|
||||
[update-parents
|
||||
{:type :mod-obj :id (:id dest-shape) :operations uoperations}])))
|
||||
|
||||
|
||||
(defn- add-update-attr-operations
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user