mirror of
https://github.com/penpot/penpot.git
synced 2025-12-12 06:24:17 +01:00
🔧 Add debug traces to detach copy operation
This commit is contained in:
@@ -36,6 +36,8 @@
|
|||||||
;; Change this to :info :debug or :trace to debug this module, or :warn to reset to default
|
;; Change this to :info :debug or :trace to debug this module, or :warn to reset to default
|
||||||
(log/set-level! :warn)
|
(log/set-level! :warn)
|
||||||
|
|
||||||
|
;; Add uuids here to filter logs to only show specific shapes or containers (and all shapes
|
||||||
|
;; contained in them).
|
||||||
(def log-shape-ids #{})
|
(def log-shape-ids #{})
|
||||||
(def log-container-ids #{})
|
(def log-container-ids #{})
|
||||||
|
|
||||||
@@ -306,55 +308,67 @@
|
|||||||
(defn- generate-detach-recursive
|
(defn- generate-detach-recursive
|
||||||
[changes container libraries shape-id first component-root?]
|
[changes container libraries shape-id first component-root?]
|
||||||
(let [shape (ctn/get-shape container shape-id)]
|
(let [shape (ctn/get-shape container shape-id)]
|
||||||
|
(shape-log :trace shape-id container
|
||||||
|
:msg " Processing" :shape-id shape-id)
|
||||||
(if (and (ctk/instance-head? shape) (not first))
|
(if (and (ctk/instance-head? shape) (not first))
|
||||||
; Subinstances are not detached
|
; Subinstances are not detached
|
||||||
(cond-> changes
|
(cond-> changes
|
||||||
component-root?
|
component-root?
|
||||||
; If the initial shape was component-root, first level subinstances are converted in top instances
|
; If the initial shape was component-root, first level subinstances are converted in top instances
|
||||||
(pcb/update-shapes [shape-id] #(assoc % :component-root true))
|
(pcb/update-shapes [shape-id] #(do (log/trace :msg " -> promote to root")
|
||||||
|
(assoc % :component-root true)))
|
||||||
|
|
||||||
:always
|
:always
|
||||||
; First level subinstances of a detached component can't have swap-slot
|
; First level subinstances of a detached component can't have swap-slot
|
||||||
(pcb/update-shapes [shape-id] ctk/remove-swap-slot)
|
(pcb/update-shapes [shape-id] #(do (log/trace :msg " -> remove swap-slot")
|
||||||
|
(ctk/remove-swap-slot %)))
|
||||||
|
|
||||||
(nil? (ctk/get-swap-slot shape))
|
(nil? (ctk/get-swap-slot shape))
|
||||||
; Near shape-refs need to be advanced one level (except if the head is already swapped)
|
; Near shape-ref of shape and children need to be advanced one level
|
||||||
|
; (except if the head is already swapped)
|
||||||
(generate-advance-nesting-level nil container libraries (:id shape)))
|
(generate-advance-nesting-level nil container libraries (:id shape)))
|
||||||
|
|
||||||
;; Otherwise, detach the shape and all children
|
;; Otherwise, detach the shape and all children
|
||||||
(let [children-ids (:shapes shape)]
|
(let [children-ids (:shapes shape)]
|
||||||
|
(log/trace :msg " -> detach")
|
||||||
(reduce #(generate-detach-recursive %1 container libraries %2 false component-root?)
|
(reduce #(generate-detach-recursive %1 container libraries %2 false component-root?)
|
||||||
(pcb/update-shapes changes [(:id shape)] ctk/detach-shape)
|
(pcb/update-shapes changes [(:id shape)] ctk/detach-shape)
|
||||||
children-ids)))))
|
children-ids)))))
|
||||||
|
|
||||||
(defn- generate-advance-nesting-level
|
(defn- generate-advance-nesting-level
|
||||||
[changes file container libraries shape-id]
|
[changes file container libraries shape-id]
|
||||||
(let [children (cfh/get-children-with-self (:objects container) shape-id)
|
(log/trace :msg " -> advance-nesting-level")
|
||||||
|
(let [children (cfh/get-children-with-self (:objects container) shape-id)
|
||||||
skip-near (fn [changes shape]
|
skip-near (fn [changes shape]
|
||||||
|
(shape-log :trace (:id shape) container
|
||||||
|
:msg " * advancing" :shape-id (:id shape))
|
||||||
(let [ref-shape (ctf/find-ref-shape file container libraries shape {:include-deleted? true})]
|
(let [ref-shape (ctf/find-ref-shape file container libraries shape {:include-deleted? true})]
|
||||||
(cond-> changes
|
(cond-> changes
|
||||||
(some? (:shape-ref ref-shape))
|
(some? (:shape-ref ref-shape))
|
||||||
(pcb/update-shapes [(:id shape)] #(assoc % :shape-ref (:shape-ref ref-shape)))
|
(pcb/update-shapes [(:id shape)] #(do (log/trace :msg " (advanced)")
|
||||||
|
(assoc % :shape-ref (:shape-ref ref-shape))))
|
||||||
|
|
||||||
;; When advancing level, the normal touched groups (not swap slots) of the
|
;; When advancing level, the normal touched groups (not swap slots) of the
|
||||||
;; ref-shape must be merged into the current shape, because they refer to
|
;; ref-shape must be merged into the current shape, because they refer to
|
||||||
;; the new referenced shape.
|
;; the new referenced shape.
|
||||||
(some? ref-shape)
|
(some? ref-shape)
|
||||||
(pcb/update-shapes
|
(pcb/update-shapes
|
||||||
[(:id shape)]
|
[(:id shape)]
|
||||||
#(assoc % :touched
|
#(do (log/trace :msg " (merge touched)")
|
||||||
(clojure.set/union (:touched shape)
|
(assoc % :touched
|
||||||
(ctk/normal-touched-groups ref-shape))))
|
(clojure.set/union (:touched shape)
|
||||||
|
(ctk/normal-touched-groups ref-shape)))))
|
||||||
|
|
||||||
;; Swap slot must also be copied if the current shape has not any,
|
;; Swap slot must also be copied if the current shape has not any,
|
||||||
;; except if this is the first level subcopy.
|
;; except if this is the first level subcopy.
|
||||||
(and (some? (ctk/get-swap-slot ref-shape))
|
(and (some? (ctk/get-swap-slot ref-shape))
|
||||||
(nil? (ctk/get-swap-slot shape))
|
(nil? (ctk/get-swap-slot shape))
|
||||||
(not= (:id shape) shape-id))
|
(not= (:id shape) shape-id))
|
||||||
(pcb/update-shapes [(:id shape)] #(ctk/set-swap-slot % (ctk/get-swap-slot ref-shape)))
|
(pcb/update-shapes [(:id shape)] #((do (log/trace :msg " (got swap-slot)")
|
||||||
|
(ctk/set-swap-slot % (ctk/get-swap-slot ref-shape)))))
|
||||||
|
|
||||||
;; If we can't get the ref-shape (e.g. it's in an external library not linked),
|
;; If we can't get the ref-shape (e.g. it's in an external library not linked),
|
||||||
;: we can't do a suitable advance. So it's better to detach the shape
|
;: we can't do a suitable advance. So it's better to detach the shape
|
||||||
(nil? ref-shape)
|
(nil? ref-shape)
|
||||||
(pcb/update-shapes [(:id shape)] ctk/detach-shape))))]
|
(pcb/update-shapes [(:id shape)] ctk/detach-shape))))]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user