0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-22 22:49:01 -05:00

🐛 Fix when changing order on main+flex, the copies are badly updated

This commit is contained in:
Pablo Alba 2023-11-30 19:34:59 +01:00 committed by Andrés Moya
parent 76ec610d44
commit 3e965c96e7
3 changed files with 13 additions and 11 deletions

View file

@ -467,7 +467,7 @@
(d/update-in-when data [:components component-id :objects] reg-objects))))
(defmethod process-change :mov-objects
[data {:keys [parent-id shapes index page-id component-id ignore-touched after-shape component-swap]}]
[data {:keys [parent-id shapes index page-id component-id ignore-touched after-shape component-swap syncing]}]
(letfn [(calculate-invalid-targets [objects shape-id]
(let [reduce-fn #(into %1 (calculate-invalid-targets objects %2))]
(->> (get-in objects [shape-id :shapes])
@ -475,15 +475,15 @@
;; Avoid placing a shape as a direct or indirect child of itself,
;; or inside its main component if it's in a copy,
;; or inside a copy
;; or inside a copy, or from a copy
(is-valid-move? [objects shape-id]
(let [invalid-targets (calculate-invalid-targets objects shape-id)
shape (get objects shape-id)
_ (prn "is-valid-move?")]
shape (get objects shape-id)]
(and shape
(not (invalid-targets parent-id))
(not (cfh/components-nesting-loop? objects shape-id parent-id))
(or component-swap
(or component-swap ;; On a component swap it's allowed to change the structure of a copy
syncing ;; If we are syncing the changes of a main component, it's allowed to change the structure of a copy
(and
(not (ctk/in-component-copy? (get objects (:parent-id shape)))) ;; We don't want to change the structure of component copies
(not (ctk/in-component-copy? (get objects parent-id)))))))) ;; We need to check the origin and target frames

View file

@ -946,16 +946,16 @@
changes (pcb/concat-changes library-changes file-changes)
find-shape (fn [data]
(for [page-id [(:page-id data)]
id (:shapes data)]
extract-shapes (fn [change]
(for [page-id [(:page-id change)]
id (:shapes change)]
(-> (get-in state [:workspace-data :pages-index page-id :objects id])
(assoc :page-id page-id))))
updated-copies (->> changes
:redo-changes
(filter #(= (:type %) :reg-objects))
(mapcat find-shape)
(mapcat extract-shapes)
(filter ctk/instance-head?)
distinct)]

View file

@ -1141,14 +1141,16 @@
:parent-id (:parent-id shape)
:shapes [(:id shape)]
:index index-after
:ignore-touched true}))
:ignore-touched true
:syncing true}))
(update :undo-changes conj (make-change
container
{:type :mov-objects
:parent-id (:parent-id shape)
:shapes [(:id shape)]
:index index-before
:ignore-touched true})))]
:ignore-touched true
:syncing true})))]
(if (and (cfh/touched-group? parent :shapes-group) omit-touched?)
changes