mirror of
https://github.com/penpot/penpot.git
synced 2025-05-02 21:05:54 +02:00
🐛 Handle swapped nested instances when detaching
This commit is contained in:
parent
d95551e651
commit
202762027f
2 changed files with 38 additions and 24 deletions
|
@ -15,6 +15,7 @@
|
||||||
- Fix incorrect uuid parsing from different parts of code
|
- Fix incorrect uuid parsing from different parts of code
|
||||||
- Fix update layout on component restore [Taiga #10637](https://tree.taiga.io/project/penpot/issue/10637)
|
- Fix update layout on component restore [Taiga #10637](https://tree.taiga.io/project/penpot/issue/10637)
|
||||||
- Fix horizontal scroll in viewer [Github #6290](https://github.com/penpot/penpot/issues/6290)
|
- Fix horizontal scroll in viewer [Github #6290](https://github.com/penpot/penpot/issues/6290)
|
||||||
|
- Fix detach component in a particular case [Taiga #10837](https://tree.taiga.io/project/penpot/issue/10837)
|
||||||
|
|
||||||
## 2.6.1
|
## 2.6.1
|
||||||
|
|
||||||
|
|
|
@ -295,6 +295,7 @@
|
||||||
|
|
||||||
(declare generate-detach-recursive)
|
(declare generate-detach-recursive)
|
||||||
(declare generate-advance-nesting-level)
|
(declare generate-advance-nesting-level)
|
||||||
|
(declare generate-detach-immediate)
|
||||||
|
|
||||||
(defn generate-detach-instance
|
(defn generate-detach-instance
|
||||||
"Generate changes to remove the links between a shape and all its children
|
"Generate changes to remove the links between a shape and all its children
|
||||||
|
@ -338,10 +339,14 @@
|
||||||
(defn- generate-advance-nesting-level
|
(defn- generate-advance-nesting-level
|
||||||
[changes file container libraries shape-id]
|
[changes file container libraries shape-id]
|
||||||
(log/trace :msg " -> advance-nesting-level")
|
(log/trace :msg " -> advance-nesting-level")
|
||||||
(let [children (cfh/get-children-with-self (:objects container) shape-id)
|
(let [detached-ids (atom #{})
|
||||||
skip-near (fn [changes shape]
|
children (cfh/get-children-with-self (:objects container) shape-id) ;; TODO: this function should be refactored to be a recursive tree traversal.
|
||||||
(shape-log :trace (:id shape) container
|
skip-near (fn [changes shape] ;; this way we could shake the tree more easily when detaching shapes
|
||||||
:msg " * advancing" :shape-id (:id shape))
|
(shape-log :trace (:id shape) container ;; and perhaps even allow to recover nested instances that have been
|
||||||
|
:msg " * advancing" :shape-id (:id shape)) ;; swapped and so we can access the main instance again.
|
||||||
|
(if (contains? @detached-ids (:id shape))
|
||||||
|
(do (log/trace :msg " (detached)")
|
||||||
|
changes)
|
||||||
(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))
|
||||||
|
@ -364,16 +369,24 @@
|
||||||
(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)] #((do (log/trace :msg " (got swap-slot)")
|
(pcb/update-shapes [(:id shape)] #(do (log/trace :msg " (got swap-slot)")
|
||||||
(ctk/set-swap-slot % (ctk/get-swap-slot ref-shape)))))
|
(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 and all its
|
||||||
|
;; children (and add to detached-ids so they are not processed again).
|
||||||
(nil? ref-shape)
|
(nil? ref-shape)
|
||||||
(pcb/update-shapes [(:id shape)] ctk/detach-shape))))]
|
(generate-detach-immediate container (:id shape) detached-ids)))))]
|
||||||
|
|
||||||
(reduce skip-near changes children)))
|
(reduce skip-near changes children)))
|
||||||
|
|
||||||
|
(defn- generate-detach-immediate
|
||||||
|
[changes container shape-id detached-ids]
|
||||||
|
(let [shape-and-children (cfh/get-children-ids-with-self (:objects container) shape-id)]
|
||||||
|
(log/trace :msg " (cannot advance; detach shape and children)")
|
||||||
|
(swap! detached-ids #(into % shape-and-children))
|
||||||
|
(pcb/update-shapes changes shape-and-children ctk/detach-shape)))
|
||||||
|
|
||||||
(defn prepare-restore-component
|
(defn prepare-restore-component
|
||||||
([changes library-data component-id current-page]
|
([changes library-data component-id current-page]
|
||||||
(let [component (ctkl/get-deleted-component library-data component-id)
|
(let [component (ctkl/get-deleted-component library-data component-id)
|
||||||
|
|
Loading…
Add table
Reference in a new issue