0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 15:09:10 -05:00

🐛 Limit reset overrides on swapped components to affected subtree

This commit is contained in:
Alejandro Alonso 2024-03-20 07:34:39 +01:00 committed by Andrés Moya
parent ef2dfe5888
commit 8f156a7fd0
2 changed files with 43 additions and 8 deletions

View file

@ -706,6 +706,38 @@
(rx/take-until stopper-s)))))) (rx/take-until stopper-s))))))
(defn sync-head
[id]
(ptk/reify ::sync-head
ptk/WatchEvent
(watch [it state _]
(log/info :msg "SYNC-head of shape" :id (str id))
(let [file (wsh/get-local-file state)
file-full (wsh/get-local-file-full state)
libraries (wsh/get-libraries state)
page-id (:current-page-id state)
container (cfh/get-container file :page page-id)
objects (:objects container)
shape-inst (ctn/get-shape container id)
parent (get objects (:parent-id shape-inst))
head (ctn/get-component-shape container parent)
components-v2
(features/active-feature? state "components/v2")
changes
(-> (pcb/empty-changes it)
(pcb/with-container container)
(pcb/with-objects (:objects container))
(dwlh/generate-sync-shape-direct file-full libraries container (:id head) false components-v2))]
(log/debug :msg "SYNC-head finished" :js/rchanges (log-changes
(:redo-changes changes)
file))
(rx/of (dch/commit-changes changes))))))
(defn reset-component (defn reset-component
"Cancels all modifications in the shape with the given id, and all its children, in "Cancels all modifications in the shape with the given id, and all its children, in
the current page. Set all attributes equal to the ones in the linked component, the current page. Set all attributes equal to the ones in the linked component,
@ -726,23 +758,26 @@
components-v2 components-v2
(features/active-feature? state "components/v2") (features/active-feature? state "components/v2")
shape-inst (ctn/get-shape container id)
swap-slot (-> (ctn/get-shape container id) swap-slot (-> (ctn/get-shape container id)
(ctk/get-swap-slot)) (ctk/get-swap-slot))
undo-id (js/Symbol)
changes changes
(-> (pcb/empty-changes it) (-> (pcb/empty-changes it)
(pcb/with-container container) (pcb/with-container container)
(pcb/with-objects (:objects container)) (pcb/with-objects (:objects container))
(dwlh/generate-sync-shape-direct file-full libraries container id true components-v2) (dwlh/generate-sync-shape-direct file-full libraries container id true components-v2))]
(cond->
(some? swap-slot)
;; We need to propagate parent changes
(dwlh/generate-sync-shape-direct file-full libraries container (:parent-id shape-inst) true components-v2)))]
(log/debug :msg "RESET-COMPONENT finished" :js/rchanges (log-changes (log/debug :msg "RESET-COMPONENT finished" :js/rchanges (log-changes
(:redo-changes changes) (:redo-changes changes)
file)) file))
(rx/of (dch/commit-changes changes)))))) (rx/of
(dwu/start-undo-transaction undo-id)
(dch/commit-changes changes)
(when (some? swap-slot)
(sync-head id))
(dwu/commit-undo-transaction undo-id))))))
(defn reset-components (defn reset-components
"Cancels all modifications in the shapes with the given ids" "Cancels all modifications in the shapes with the given ids"

View file

@ -588,7 +588,7 @@
(t/is (= (:fill-color shape1) clr/black)) (t/is (= (:fill-color shape1) clr/black))
(t/is (= (:fill-opacity shape1) 0)) (t/is (= (:fill-opacity shape1) 0))
(t/is (= (:name shape2) "Rect 1")) (t/is (= (:name shape2) "Rect 1"))
(t/is (= (:touched shape2) nil)) (t/is (= (:touched shape2) #{:fill-group}))
(t/is (= (:fill-color shape2) clr/test)) (t/is (= (:fill-color shape2) clr/test))
(t/is (= (:fill-opacity shape2) 0.5)) (t/is (= (:fill-opacity shape2) 0.5))
(t/is (= (:name c-instance2) "Board")) (t/is (= (:name c-instance2) "Board"))