0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 08:20:45 -05:00

🐛 Fix swap slots when detaching a copy with subcopies

This commit is contained in:
Andrés Moya 2024-06-11 17:14:28 +02:00
parent 058a72b817
commit 03aa0817f7
4 changed files with 37 additions and 17 deletions

View file

@ -184,10 +184,7 @@
(ctk/instance-head? child))
(let [slot (guess-swap-slot component-child component-container)]
(l/dbg :hint "child" :id (:id child) :name (:name child) :slot slot)
(ctn/update-shape container (:id child)
#(update % :touched
cfh/set-touched-group
(ctk/build-swap-slot-group slot))))
(ctn/update-shape container (:id child) #(ctk/set-swap-slot % slot)))
container)]
(recur (process-copy-head container child)
(rest children)

View file

@ -481,7 +481,7 @@
(let [slot (:swap-slot args)]
(when (some? slot)
(log/debug :hint (str " -> set swap-slot to " slot))
(update shape :touched cfh/set-touched-group (ctk/build-swap-slot-group slot)))))]
(ctk/set-swap-slot shape slot))))]
(log/dbg :hint "repairing shape :missing-slot" :id (:id shape) :name (:name shape) :page-id page-id)
(-> (pcb/empty-changes nil page-id)

View file

@ -284,9 +284,17 @@
(let [children (cfh/get-children-with-self (:objects container) shape-id)
skip-near (fn [changes shape]
(let [ref-shape (ctf/find-ref-shape file container libraries shape {:include-deleted? true})]
(if (some? (:shape-ref ref-shape))
(pcb/update-shapes changes [(:id shape)] #(assoc % :shape-ref (:shape-ref ref-shape)))
changes)))]
(cond-> changes
(some? (:shape-ref ref-shape))
(pcb/update-shapes [(:id shape)] #(assoc % :shape-ref (:shape-ref ref-shape)))
;; When advancing level, if the referenced shape has a swap slot, it must be
;; copied to the current shape, because the shape-ref now will not be pointing
;; to a near main (except for first level subcopies).
(and (some? (ctk/get-swap-slot ref-shape))
(nil? (ctk/get-swap-slot shape))
(not= (:id shape) shape-id))
(pcb/update-shapes [(:id shape)] #(ctk/set-swap-slot % (ctk/get-swap-slot ref-shape))))))]
(reduce skip-near changes children)))
(defn prepare-restore-component
@ -1194,7 +1202,7 @@
:shapes all-parents}))
changes' (reduce del-obj-change changes' new-shapes)]
(if (and (cfh/touched-group? parent-shape :shapes-group) omit-touched?)
(if (and (ctk/touched-group? parent-shape :shapes-group) omit-touched?)
changes
changes')))
@ -1349,7 +1357,7 @@
changes'
ids)]
(if (and (cfh/touched-group? parent :shapes-group) omit-touched?)
(if (and (ctk/touched-group? parent :shapes-group) omit-touched?)
changes
changes')))
@ -1385,7 +1393,7 @@
:ignore-touched true
:syncing true})))]
(if (and (cfh/touched-group? parent :shapes-group) omit-touched?)
(if (and (ctk/touched-group? parent :shapes-group) omit-touched?)
changes
changes')))
@ -1846,12 +1854,11 @@
;; if the shape isn't inside a main component, it shouldn't have a swap slot
(and (nil? (ctk/get-swap-slot new-shape))
inside-comp?)
(update :touched cfh/set-touched-group (-> (ctf/find-swap-slot shape
page
{:id (:id file)
:data file}
libraries)
(ctk/build-swap-slot-group))))]
(ctk/set-swap-slot (ctf/find-swap-slot shape
page
{:id (:id file)
:data file}
libraries)))]
[new-shape (-> changes
;; Restore the properties

View file

@ -183,6 +183,15 @@
(and (= shape-id (:main-instance-id component))
(= page-id (:main-instance-page component))))
(defn set-touched-group
[touched group]
(when group
(conj (or touched #{}) group)))
(defn touched-group?
[shape group]
((or (:touched shape) #{}) group))
(defn build-swap-slot-group
"Convert a swap-slot into a :touched group"
[swap-slot]
@ -204,6 +213,13 @@
(when group
(group->swap-slot group))))
(defn set-swap-slot
"Add a touched group with a form :swap-slot-<uuid>."
[shape swap-slot]
(cond-> shape
(some? swap-slot)
(update :touched set-touched-group (build-swap-slot-group swap-slot))))
(defn match-swap-slot?
[shape-main shape-inst]
(let [slot-main (get-swap-slot shape-main)