🐛 Fix touched on adding shapes to a component copy and undo

This commit is contained in:
Andrés Moya 2023-06-21 14:38:09 +02:00 committed by Andrey Antukh
parent d4fe810813
commit d8121364ad
7 changed files with 41 additions and 10 deletions

View file

@ -15,6 +15,7 @@
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
[app.common.types.component :as ctk]
[app.common.types.file :as ctf] [app.common.types.file :as ctf]
[app.common.uuid :as uuid])) [app.common.uuid :as uuid]))
@ -216,9 +217,14 @@
([changes obj {:keys [index ignore-touched] :or {index ::undefined ignore-touched false}}] ([changes obj {:keys [index ignore-touched] :or {index ::undefined ignore-touched false}}]
(assert-page-id changes) (assert-page-id changes)
(assert-objects changes)
(let [obj (cond-> obj (let [obj (cond-> obj
(not= index ::undefined) (not= index ::undefined)
(assoc ::index index)) (assoc ::index index))
objects (lookup-objects changes)
parent (get objects (:parent-id obj))
add-change add-change
{:type :add-obj {:type :add-obj
:id (:id obj) :id (:id obj)
@ -232,10 +238,20 @@
del-change del-change
{:type :del-obj {:type :del-obj
:id (:id obj) :id (:id obj)
:page-id (::page-id (meta changes))}] :page-id (::page-id (meta changes))}
restore-touched-change
{:type :mod-obj
:page-id (::page-id (meta changes))
:id (:id parent)
:operations [{:type :set-touched
:touched (:touched parent)}]}]
(-> changes (-> changes
(update :redo-changes conj add-change) (update :redo-changes conj add-change)
(cond->
(and (ctk/in-component-copy? parent) (not ignore-touched))
(update :undo-changes d/preconj restore-touched-change))
(update :undo-changes d/preconj del-change) (update :undo-changes d/preconj del-change)
(apply-changes-local))))) (apply-changes-local)))))
@ -256,6 +272,8 @@
(assert-page-id changes) (assert-page-id changes)
(assert-objects changes) (assert-objects changes)
(let [objects (lookup-objects changes) (let [objects (lookup-objects changes)
parent (get objects parent-id)
set-parent-change set-parent-change
(cond-> {:type :mov-objects (cond-> {:type :mov-objects
:parent-id parent-id :parent-id parent-id
@ -275,10 +293,20 @@
:parent-id (:parent-id shape) :parent-id (:parent-id shape)
:shapes [(:id shape)] :shapes [(:id shape)]
:after-shape prev-sibling :after-shape prev-sibling
:index 0})))] ; index is used in case there is no after-shape (moving bottom shapes) :index 0}))) ; index is used in case there is no after-shape (moving bottom shapes)
restore-touched-change
{:type :mod-obj
:page-id (::page-id (meta changes))
:id (:id parent)
:operations [{:type :set-touched
:touched (:touched parent)}]}]
(-> changes (-> changes
(update :redo-changes conj set-parent-change) (update :redo-changes conj set-parent-change)
(cond->
(ctk/in-component-copy? parent)
(update :undo-changes d/preconj restore-touched-change))
(update :undo-changes #(reduce mk-undo-change % shapes)) (update :undo-changes #(reduce mk-undo-change % shapes))
(apply-changes-local))))) (apply-changes-local)))))

View file

@ -39,9 +39,7 @@
(-> parent (-> parent
(update :shapes update-parent-shapes) (update :shapes update-parent-shapes)
(update :shapes d/vec-without-nils) (update :shapes d/vec-without-nils)
(cond-> (and (:shape-ref parent) (cond-> (and (ctk/in-component-copy? parent) (not ignore-touched))
(not= (:id parent) frame-id)
(not ignore-touched))
(-> (update :touched cph/set-touched-group :shapes-group) (-> (update :touched cph/set-touched-group :shapes-group)
(dissoc :remote-synced?))))) (dissoc :remote-synced?)))))

View file

@ -485,7 +485,8 @@
(let [page (wsh/lookup-page state) (let [page (wsh/lookup-page state)
libraries (wsh/get-libraries state) libraries (wsh/get-libraries state)
changes (pcb/empty-changes it (:id page)) changes (-> (pcb/empty-changes it (:id page))
(pcb/with-objects (:objects page)))
[new-shape changes] [new-shape changes]
(dwlh/generate-instantiate-component changes (dwlh/generate-instantiate-component changes

View file

@ -228,6 +228,7 @@
(assoc :parent-id parent-id)) (assoc :parent-id parent-id))
changes (-> (or changes (pcb/empty-changes it)) changes (-> (or changes (pcb/empty-changes it))
(pcb/with-page page) (pcb/with-page page)
(pcb/with-objects (:objects page))
(pcb/with-library-data library-data)) (pcb/with-library-data library-data))
changes (cond-> (pcb/add-object changes first-shape {:ignore-touched true}) changes (cond-> (pcb/add-object changes first-shape {:ignore-touched true})
(some? old-id) (pcb/amend-last-change #(assoc % :old-id old-id))) ; on copy/paste old id is used later to reorder the paster layers (some? old-id) (pcb/amend-last-change #(assoc % :old-id old-id))) ; on copy/paste old id is used later to reorder the paster layers

View file

@ -433,7 +433,7 @@
(gsh/move delta) (gsh/move delta)
(d/update-when :interactions #(ctsi/remap-interactions % ids-map objects))) (d/update-when :interactions #(ctsi/remap-interactions % ids-map objects)))
changes (-> (pcb/add-object changes new-obj {:ignore-touched true}) changes (-> (pcb/add-object changes new-obj)
(pcb/amend-last-change #(assoc % :old-id (:id obj)))) (pcb/amend-last-change #(assoc % :old-id (:id obj))))
changes (cond-> changes changes (cond-> changes

View file

@ -108,7 +108,8 @@
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)
changes (pcb/empty-changes it page-id) changes (-> (pcb/empty-changes it page-id)
(pcb/with-objects objects))
[shape changes] [shape changes]
(prepare-add-shape changes attrs objects selected) (prepare-add-shape changes attrs objects selected)
@ -433,7 +434,8 @@
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)
selected (cph/clean-loops objects selected) selected (cph/clean-loops objects selected)
changes (pcb/empty-changes it page-id) changes (-> (pcb/empty-changes it page-id)
(pcb/with-objects objects))
[frame-shape changes] [frame-shape changes]
(prepare-create-artboard-from-selection changes (prepare-create-artboard-from-selection changes

View file

@ -154,7 +154,8 @@
(let [page (current-page state) (let [page (current-page state)
libraries (wsh/get-libraries state) libraries (wsh/get-libraries state)
changes (pcb/empty-changes nil (:id page)) changes (-> (pcb/empty-changes nil (:id page))
(pcb/with-objects (:objects page)))
[new-shape changes] [new-shape changes]
(dwlh/generate-instantiate-component changes (dwlh/generate-instantiate-component changes