mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Keep a plain swap's inherited orientation through sync
A plain swap also retains orientation inherited from its old component. Record that retained orientation as geometry when it differs from the new component's expected placement. Parent-derived orientation stays untouched and size-only overrides still clear. The regression fails before the fix. The swap suite passes 41 tests / 162 assertions; the seeded MVP property also passes 100 scenarios. Benchmark vs Phase 1e: main 10/100/1000 0.54/0.57/0.66; levels 0.60; chain 0.62; library 0.67; many shapes 0.83; switch 0.77. No flags. AI-assisted-by: GPT-6
This commit is contained in:
parent
b6ae3db002
commit
66c254fbc6
@ -445,9 +445,9 @@
|
||||
(when-let [parent (get objects parent-id)]
|
||||
(or (d/index-of (:shapes parent) shape-id) 0)))
|
||||
|
||||
(defn- keep-authored-orientation
|
||||
"A plain swap drops content overrides, but keeps an authored rotation or
|
||||
flip as geometry so a later sync does not remove its retained placement."
|
||||
(defn- keep-orientation-override
|
||||
"A plain swap keeps its old orientation. When that differs from the new
|
||||
component's expected placement, the swap authors a geometry override."
|
||||
[changes shape baseline page ldata component-id]
|
||||
(let [parent (get-in page [:objects (:parent-id shape)])
|
||||
main (ctf/get-component-root ldata (ctkl/get-component ldata component-id))
|
||||
@ -465,7 +465,7 @@
|
||||
(not= (boolean (:flip-x shape)) (flip :flip-x))
|
||||
(not= (boolean (:flip-y shape)) (flip :flip-y)))]
|
||||
(cond-> changes
|
||||
(and (ctk/touched-group? shape :geometry-group) changed?)
|
||||
changed?
|
||||
(pcb/update-shapes [(:id shape)]
|
||||
#(update % :touched (fnil conj #{}) :geometry-group)
|
||||
{:ignore-touched true}))))
|
||||
@ -494,7 +494,7 @@
|
||||
[changes parents-of-swapped]
|
||||
(if keep-touched?
|
||||
(generate-keep-touched changes new-shape shape orig-shapes page libraries ldata)
|
||||
[(keep-authored-orientation changes shape new-shape page ldata component-id) []])
|
||||
[(keep-orientation-override changes shape new-shape page ldata component-id) []])
|
||||
|
||||
;; Replacement keeps the head id and its cell. Cleanup during the
|
||||
;; temporary deletion must not change the parent's placement data.
|
||||
|
||||
@ -734,3 +734,15 @@
|
||||
(t/is (mth/close? 0 (:rotation child) 0.001))
|
||||
(t/is (= #{:swap-group} (:touched head)))
|
||||
(t/is (nil? (:touched child)))))
|
||||
|
||||
(t/deftest plain-swap-keeps-the-orientation-inherited-from-its-old-component
|
||||
(let [initial (-> (tm/make-situation (setup-sized))
|
||||
(r/step (n/rotate :star-main 45)) r/settle)
|
||||
swapped (-> initial (r/step (n/swap-shape :card-star :heart)) r/settle)
|
||||
head (tm/resolve-shape swapped :card-star)
|
||||
file (tm/file swapped)
|
||||
full (:file (r/sync-cascade file {} (keys (get-in file [:data :components]))))]
|
||||
(t/is (nil? (:touched (tm/resolve-shape initial :card-star))))
|
||||
(t/is (ctk/touched-group? head :geometry-group))
|
||||
(t/is (mth/close? 45 (:rotation head) 0.001))
|
||||
(t/is (= (orientation file :card-star) (orientation full :card-star)))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user