mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Sync content from the restored position after a swap back
A swap back relinks to its near position and clears the swap marker. Sync through the enclosing copy that owns those refs so its content overrides reach the restored head and children. Keep carried overrides and unrelated sibling overrides intact. Portable regression: three failures before the fix, then all assertions pass, including exact undo. Focused JVM and golden checks: 183 tests, 2143 assertions. The original and newly shrunk library programs pass. Live WASM verifies plain and variant swaps, later propagation, carried opacity and an unrelated sibling override. Common/frontend lint and fmt pass. Component benchmark ratios: mains 0.61/0.80/0.85; levels 0.71; chain 0.73; library 0.52; many shapes 0.53; variant switch 0.62. All worlds pass the unchanged baseline gate. AI-assisted-by: GPT-6
This commit is contained in:
parent
964433cfc6
commit
d0191c2a31
@ -493,6 +493,23 @@
|
||||
(when-let [parent (get objects parent-id)]
|
||||
(or (d/index-of (:shapes parent) shape-id) 0)))
|
||||
|
||||
(defn- sync-restored-position
|
||||
"A swap back is an ordinary copy of its position, including that
|
||||
position's content overrides. Sync through the head that owns its ref."
|
||||
[changes page libraries shape-id]
|
||||
(let [objects (pcb/get-objects changes)
|
||||
shape (get objects shape-id)
|
||||
parent (get objects (:parent-id shape))
|
||||
container (ctn/make-container (assoc page :objects objects) :page)]
|
||||
(if (and (:shape-ref parent) (not (ctk/swapped? shape)))
|
||||
(let [component (ctf/find-ref-component nil container libraries shape)
|
||||
head (d/seek #(= (:id component) (:component-id %))
|
||||
(ctn/get-parent-copy-heads objects parent))]
|
||||
(if head
|
||||
(cll/generate-sync-shape-direct changes nil libraries container (:id head) false)
|
||||
changes))
|
||||
changes)))
|
||||
|
||||
(defn generate-component-swap-in-place
|
||||
"Swap the copy head `shape` of `page` for a copy of the component
|
||||
`component-id` of library data `ldata`. The new head takes the old one's
|
||||
@ -522,6 +539,8 @@
|
||||
(ctf/find-ref-shape nil page libraries shape
|
||||
:include-deleted? true :with-context? true))) []])
|
||||
|
||||
changes (sync-restored-position changes page libraries (:id new-shape))
|
||||
|
||||
;; Replacement keeps the head id and its cell. Cleanup during the
|
||||
;; temporary deletion must not change the parent's placement data.
|
||||
changes (cond-> changes
|
||||
|
||||
@ -966,3 +966,22 @@
|
||||
(t/is (= (:fills main-child) (:fills (ths/get-shape-by-id full (:id main-child)))))
|
||||
(t/is (= (thn/normalize-file (tm/file edited))
|
||||
(thn/normalize-file (tm/file (r/step updated (n/undo))))))))
|
||||
|
||||
(t/deftest swapping-back-inherits-the-new-positions-content-overrides
|
||||
(let [initial (tm/make-situation (setup))
|
||||
child-id (first (:shapes (tm/resolve-shape initial :card-star)))
|
||||
edited (-> initial
|
||||
(r/step (n/change-property :card-star :fills "#333333")) r/settle
|
||||
(r/step (n/change-property (constantly child-id) :fills "#444444")) r/settle)
|
||||
swapped (-> edited (r/step (n/swap-shape :copy-star :star)) r/settle)
|
||||
head (tm/resolve-shape swapped :copy-star)
|
||||
child (tm/shape-by-id swapped (first (:shapes head)))
|
||||
file (tm/file swapped)
|
||||
full (:file (r/sync-cascade file {} (keys (get-in file [:data :components]))))]
|
||||
(t/is (= "#333333" (get-in head [:fills 0 :fill-color])))
|
||||
(t/is (= "#444444" (get-in child [:fills 0 :fill-color])))
|
||||
(t/is (empty? (:touched head)))
|
||||
(t/is (empty? (:touched child)))
|
||||
(t/is (= (:fills head) (:fills (ths/get-shape-by-id full (:id head)))))
|
||||
(t/is (= (thn/normalize-file (tm/file edited))
|
||||
(thn/normalize-file (tm/file (r/step swapped (n/undo))))))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user