mirror of
https://github.com/penpot/penpot.git
synced 2025-04-16 00:41:25 -05:00
🐛 Fix touched on adding shapes to a component copy and undo
This commit is contained in:
parent
d4fe810813
commit
d8121364ad
7 changed files with 41 additions and 10 deletions
common/src/app/common
frontend
src/app/main/data/workspace
test/frontend_tests/helpers
|
@ -15,6 +15,7 @@
|
|||
[app.common.math :as mth]
|
||||
[app.common.pages :as cp]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.common.uuid :as uuid]))
|
||||
|
||||
|
@ -216,9 +217,14 @@
|
|||
|
||||
([changes obj {:keys [index ignore-touched] :or {index ::undefined ignore-touched false}}]
|
||||
(assert-page-id changes)
|
||||
(assert-objects changes)
|
||||
(let [obj (cond-> obj
|
||||
(not= index ::undefined)
|
||||
(assoc ::index index))
|
||||
|
||||
objects (lookup-objects changes)
|
||||
parent (get objects (:parent-id obj))
|
||||
|
||||
add-change
|
||||
{:type :add-obj
|
||||
:id (:id obj)
|
||||
|
@ -232,10 +238,20 @@
|
|||
del-change
|
||||
{:type :del-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
|
||||
(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)
|
||||
(apply-changes-local)))))
|
||||
|
||||
|
@ -256,6 +272,8 @@
|
|||
(assert-page-id changes)
|
||||
(assert-objects changes)
|
||||
(let [objects (lookup-objects changes)
|
||||
parent (get objects parent-id)
|
||||
|
||||
set-parent-change
|
||||
(cond-> {:type :mov-objects
|
||||
:parent-id parent-id
|
||||
|
@ -275,10 +293,20 @@
|
|||
:parent-id (:parent-id shape)
|
||||
:shapes [(:id shape)]
|
||||
: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
|
||||
(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))
|
||||
(apply-changes-local)))))
|
||||
|
||||
|
|
|
@ -39,9 +39,7 @@
|
|||
(-> parent
|
||||
(update :shapes update-parent-shapes)
|
||||
(update :shapes d/vec-without-nils)
|
||||
(cond-> (and (:shape-ref parent)
|
||||
(not= (:id parent) frame-id)
|
||||
(not ignore-touched))
|
||||
(cond-> (and (ctk/in-component-copy? parent) (not ignore-touched))
|
||||
(-> (update :touched cph/set-touched-group :shapes-group)
|
||||
(dissoc :remote-synced?)))))
|
||||
|
||||
|
|
|
@ -485,7 +485,8 @@
|
|||
(let [page (wsh/lookup-page 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]
|
||||
(dwlh/generate-instantiate-component changes
|
||||
|
|
|
@ -228,6 +228,7 @@
|
|||
(assoc :parent-id parent-id))
|
||||
changes (-> (or changes (pcb/empty-changes it))
|
||||
(pcb/with-page page)
|
||||
(pcb/with-objects (:objects page))
|
||||
(pcb/with-library-data library-data))
|
||||
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
|
||||
|
|
|
@ -433,7 +433,7 @@
|
|||
(gsh/move delta)
|
||||
(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))))
|
||||
|
||||
changes (cond-> changes
|
||||
|
|
|
@ -108,7 +108,8 @@
|
|||
objects (wsh/lookup-page-objects state page-id)
|
||||
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]
|
||||
(prepare-add-shape changes attrs objects selected)
|
||||
|
@ -433,7 +434,8 @@
|
|||
selected (wsh/lookup-selected state)
|
||||
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]
|
||||
(prepare-create-artboard-from-selection changes
|
||||
|
|
|
@ -154,7 +154,8 @@
|
|||
(let [page (current-page 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]
|
||||
(dwlh/generate-instantiate-component changes
|
||||
|
|
Loading…
Add table
Reference in a new issue