mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 09:42:01 +00:00
🐛 Keep a turned head's first corner when a switch keeps its turn
A swap gives the new head the orientation of the head it replaces and, when that turns it, puts it at the old head's first corner. A head that already had that orientation, like a flipped copy of a flipped variant, kept the untransformed top-left of the old one instead, so a wider flipped variant grew to the other side; sync and the expected placement keep a turned or flipped head's first corner. A turned or flipped head takes the place of the old one at its first corner also when its orientation does not change. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 19.42 | 0.55 | | edit-through-a-chain-of-dependents | 68.931 | 40.335 | 0.59 | | library-update-into-copies | 83.083 | 50.62 | 0.61 | | main-edit-among-many-shapes | 4.837 | 2.306 | 0.48 | | main-edit-into-10-copies | 1.79 | 0.963 | 0.54 | | main-edit-into-100-copies | 15.415 | 10.159 | 0.66 | | main-edit-into-1000-copies | 153.086 | 93.147 | 0.61 | | variant-switch-into-copies | 32.052 | 21.501 | 0.67 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
a95f26b601
commit
1f332c396f
@ -332,18 +332,28 @@
|
||||
"Give the new head of a swap, and its subtree, the flips and the rotation
|
||||
of the shape it replaces, around the head's own center. They come from
|
||||
its parent, as when the parent is rotated, and are not overrides. The
|
||||
turned head takes the place of the old one at their first corner, so it
|
||||
turns rigidly with its parent."
|
||||
turned or flipped head takes the place of the old one at their first
|
||||
corner, so it turns rigidly with its parent, also when it already has
|
||||
the old one's orientation."
|
||||
[changes new-shape shape]
|
||||
(if-let [orient (cll/orient-like new-shape shape (gsh/shape->center new-shape))]
|
||||
(let [ids (cfh/get-children-ids-with-self (pcb/get-objects changes) (:id new-shape))
|
||||
delta (gpt/subtract (first (:points shape)) (first (:points (orient new-shape))))]
|
||||
(let [orient (cll/orient-like new-shape shape (gsh/shape->center new-shape))
|
||||
ids (cfh/get-children-ids-with-self (pcb/get-objects changes) (:id new-shape))
|
||||
delta (gpt/subtract (first (:points shape))
|
||||
(first (:points (cond-> new-shape (some? orient) (orient)))))]
|
||||
(cond
|
||||
(some? orient)
|
||||
(pcb/update-shapes changes ids
|
||||
(cond->> orient
|
||||
(not (gpt/almost-zero? delta))
|
||||
(comp #(gsh/move % delta)))
|
||||
{:ignore-touched true}))
|
||||
changes))
|
||||
{:ignore-touched true})
|
||||
|
||||
(and (not (gmt/unit? (or (:transform shape) (gmt/matrix))))
|
||||
(not (gpt/almost-zero? delta)))
|
||||
(pcb/update-shapes changes ids #(gsh/move % delta) {:ignore-touched true})
|
||||
|
||||
:else
|
||||
changes)))
|
||||
|
||||
(defn- generate-swap-in-copy
|
||||
"A swap inside a copy keeps the position: the new head takes the place of
|
||||
|
||||
@ -1160,3 +1160,12 @@
|
||||
:layout-item-margins false :grid-square false :grid-empty false}]
|
||||
:ops [[:delete 0] [:restore 0] [:undo 0 0 0 0] [:delete 11] [:restore 11]
|
||||
[:delete 1 0 0 0] [:delete 3 0 0 0] [:rotate 4 0 0 0] [:detach 11 0 0 0]]}))))
|
||||
|
||||
(t/deftest generated-switch-keeps-a-flipped-heads-first-corner
|
||||
;; both variant mains are flipped; a flipped nested copy switches to the
|
||||
;; wider variant and keeps its first corner, its top right
|
||||
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :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 [[:transform 1 4 0 0] [:delete 5 0 0 0] [:delete 0] [:restore 0]
|
||||
[:transform 1 4 0 0] [:switch 0 0 0 0]]}))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user