mirror of
https://github.com/penpot/penpot.git
synced 2025-06-05 08:01:40 +02:00
🐛 Fix order of undo operations
This commit is contained in:
parent
0b984a44d7
commit
b7e0619e9a
3 changed files with 76 additions and 76 deletions
|
@ -101,7 +101,7 @@
|
|||
|
||||
(defn preconj
|
||||
[coll elem]
|
||||
(assert (vector? coll))
|
||||
(assert (or (vector? coll) (nil? coll)))
|
||||
(into [elem] coll))
|
||||
|
||||
(defn enumerate
|
||||
|
|
|
@ -124,35 +124,35 @@
|
|||
[changes id name]
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :add-page :id id :name name})
|
||||
(update :undo-changes conj {:type :del-page :id id})
|
||||
(update :undo-changes d/preconj {:type :del-page :id id})
|
||||
(apply-changes-local)))
|
||||
|
||||
(defn add-page
|
||||
[changes id page]
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :add-page :id id :page page})
|
||||
(update :undo-changes conj {:type :del-page :id id})
|
||||
(update :undo-changes d/preconj {:type :del-page :id id})
|
||||
(apply-changes-local)))
|
||||
|
||||
(defn mod-page
|
||||
[changes page new-name]
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :mod-page :id (:id page) :name new-name})
|
||||
(update :undo-changes conj {:type :mod-page :id (:id page) :name (:name page)})
|
||||
(update :undo-changes d/preconj {:type :mod-page :id (:id page) :name (:name page)})
|
||||
(apply-changes-local)))
|
||||
|
||||
(defn del-page
|
||||
[changes page]
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :del-page :id (:id page)})
|
||||
(update :undo-changes conj {:type :add-page :id (:id page) :page page})
|
||||
(update :undo-changes d/preconj {:type :add-page :id (:id page) :page page})
|
||||
(apply-changes-local)))
|
||||
|
||||
(defn move-page
|
||||
[changes page-id index prev-index]
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :mov-page :id page-id :index index})
|
||||
(update :undo-changes conj {:type :mov-page :id page-id :index prev-index})
|
||||
(update :undo-changes d/preconj {:type :mov-page :id page-id :index prev-index})
|
||||
(apply-changes-local)))
|
||||
|
||||
(defn set-page-option
|
||||
|
@ -167,7 +167,7 @@
|
|||
:page-id page-id
|
||||
:option option-key
|
||||
:value option-val})
|
||||
(update :undo-changes conj {:type :set-option
|
||||
(update :undo-changes d/preconj {:type :set-option
|
||||
:page-id page-id
|
||||
:option option-key
|
||||
:value old-val})
|
||||
|
@ -186,7 +186,7 @@
|
|||
:page-id page-id
|
||||
:option option-key
|
||||
:value new-val})
|
||||
(update :undo-changes conj {:type :set-option
|
||||
(update :undo-changes d/preconj {:type :set-option
|
||||
:page-id page-id
|
||||
:option option-key
|
||||
:value old-val})
|
||||
|
@ -280,7 +280,7 @@
|
|||
(update :rops conj {:type :set :attr attr :val new-val
|
||||
:ignore-geometry ignore-geometry?
|
||||
:ignore-touched ignore-touched})
|
||||
(update :uops conj {:type :set :attr attr :val old-val
|
||||
(update :uops d/preconj {:type :set :attr attr :val old-val
|
||||
:ignore-touched true})))))
|
||||
|
||||
update-shape
|
||||
|
@ -297,7 +297,7 @@
|
|||
|
||||
uops (cond-> uops
|
||||
(seq uops)
|
||||
(conj {:type :set-touched :touched (:touched old-obj)}))
|
||||
(d/preconj {:type :set-touched :touched (:touched old-obj)}))
|
||||
|
||||
change (cond-> {:type :mod-obj
|
||||
:id id}
|
||||
|
@ -404,7 +404,7 @@
|
|||
operations
|
||||
(-> operations
|
||||
(update :rops conj {:type :set :attr attr :val new-val :ignore-touched true})
|
||||
(update :uops conj {:type :set :attr attr :val old-val :ignore-touched true})))))
|
||||
(update :uops d/preconj {:type :set :attr attr :val old-val :ignore-touched true})))))
|
||||
|
||||
resize-parent
|
||||
(fn [changes parent]
|
||||
|
@ -452,7 +452,7 @@
|
|||
[changes color]
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :add-color :color color})
|
||||
(update :undo-changes conj {:type :del-color :id (:id color)})
|
||||
(update :undo-changes d/preconj {:type :del-color :id (:id color)})
|
||||
(apply-changes-local)))
|
||||
|
||||
(defn update-color
|
||||
|
@ -462,7 +462,7 @@
|
|||
prev-color (get-in library-data [:colors (:id color)])]
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :mod-color :color color})
|
||||
(update :undo-changes conj {:type :mod-color :color prev-color})
|
||||
(update :undo-changes d/preconj {:type :mod-color :color prev-color})
|
||||
(apply-changes-local))))
|
||||
|
||||
(defn delete-color
|
||||
|
@ -472,14 +472,14 @@
|
|||
prev-color (get-in library-data [:colors color-id])]
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :del-color :id color-id})
|
||||
(update :undo-changes conj {:type :add-color :color prev-color})
|
||||
(update :undo-changes d/preconj {:type :add-color :color prev-color})
|
||||
(apply-changes-local))))
|
||||
|
||||
(defn add-media
|
||||
[changes object]
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :add-media :object object})
|
||||
(update :undo-changes conj {:type :del-media :id (:id object)})
|
||||
(update :undo-changes d/preconj {:type :del-media :id (:id object)})
|
||||
(apply-changes-local)))
|
||||
|
||||
(defn update-media
|
||||
|
@ -489,7 +489,7 @@
|
|||
prev-object (get-in library-data [:media (:id object)])]
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :mod-media :object object})
|
||||
(update :undo-changes conj {:type :mod-media :object prev-object})
|
||||
(update :undo-changes d/preconj {:type :mod-media :object prev-object})
|
||||
(apply-changes-local))))
|
||||
|
||||
(defn delete-media
|
||||
|
@ -499,14 +499,14 @@
|
|||
prev-object (get-in library-data [:media id])]
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :del-media :id id})
|
||||
(update :undo-changes conj {:type :add-media :object prev-object})
|
||||
(update :undo-changes d/preconj {:type :add-media :object prev-object})
|
||||
(apply-changes-local))))
|
||||
|
||||
(defn add-typography
|
||||
[changes typography]
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :add-typography :typography typography})
|
||||
(update :undo-changes conj {:type :del-typography :id (:id typography)})
|
||||
(update :undo-changes d/preconj {:type :del-typography :id (:id typography)})
|
||||
(apply-changes-local)))
|
||||
|
||||
(defn update-typography
|
||||
|
@ -516,7 +516,7 @@
|
|||
prev-typography (get-in library-data [:typographies (:id typography)])]
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :mod-typography :typography typography})
|
||||
(update :undo-changes conj {:type :mod-typography :typography prev-typography})
|
||||
(update :undo-changes d/preconj {:type :mod-typography :typography prev-typography})
|
||||
(apply-changes-local))))
|
||||
|
||||
(defn delete-typography
|
||||
|
@ -526,7 +526,7 @@
|
|||
prev-typography (get-in library-data [:typographies typography-id])]
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :del-typography :id typography-id})
|
||||
(update :undo-changes conj {:type :add-typography :typography prev-typography})
|
||||
(update :undo-changes d/preconj {:type :add-typography :typography prev-typography})
|
||||
(apply-changes-local))))
|
||||
|
||||
(defn add-component
|
||||
|
@ -569,7 +569,7 @@
|
|||
(update :undo-changes
|
||||
(fn [undo-changes]
|
||||
(-> undo-changes
|
||||
(conj {:type :del-component
|
||||
(d/preconj {:type :del-component
|
||||
:id id})
|
||||
(into (comp (map :id)
|
||||
(map lookupf)
|
||||
|
@ -590,7 +590,7 @@
|
|||
:name (:name new-component)
|
||||
:path (:path new-component)
|
||||
:objects (:objects new-component)})
|
||||
(update :undo-changes conj {:type :mod-component
|
||||
(update :undo-changes d/preconj {:type :mod-component
|
||||
:id id
|
||||
:name (:name prev-component)
|
||||
:path (:path prev-component)
|
||||
|
@ -605,7 +605,7 @@
|
|||
(-> changes
|
||||
(update :redo-changes conj {:type :del-component
|
||||
:id id})
|
||||
(update :undo-changes conj {:type :add-component
|
||||
(update :undo-changes d/preconj {:type :add-component
|
||||
:id id
|
||||
:name (:name prev-component)
|
||||
:path (:path prev-component)
|
||||
|
|
|
@ -357,7 +357,7 @@
|
|||
:operations [{:type :set
|
||||
:attr :content
|
||||
:val new-content}]}))
|
||||
(update :undo-changes conj (make-change
|
||||
(update :undo-changes d/preconj (make-change
|
||||
container
|
||||
{:type :mod-obj
|
||||
:id (:id shape)
|
||||
|
@ -915,7 +915,7 @@
|
|||
(assoc :frame-id (:frame-id shape')))))))
|
||||
|
||||
del-obj-change (fn [changes shape']
|
||||
(update changes :undo-changes conj
|
||||
(update changes :undo-changes d/preconj
|
||||
(make-change
|
||||
container
|
||||
{:type :del-obj
|
||||
|
@ -994,7 +994,7 @@
|
|||
:val (:touched shape')}]}))
|
||||
|
||||
del-obj-change (fn [changes shape']
|
||||
(update changes :undo-changes conj
|
||||
(update changes :undo-changes d/preconj
|
||||
{:type :del-obj
|
||||
:id (:id shape')
|
||||
:page-id (:id page)
|
||||
|
@ -1021,7 +1021,7 @@
|
|||
|
||||
add-undo-change (fn [changes id]
|
||||
(let [shape' (get objects id)]
|
||||
(update changes :undo-changes conj
|
||||
(update changes :undo-changes d/preconj
|
||||
(make-change
|
||||
container
|
||||
(as-> {:type :add-obj
|
||||
|
@ -1073,7 +1073,7 @@
|
|||
:shapes [(:id shape)]
|
||||
:index index-after
|
||||
:ignore-touched true}))
|
||||
(update :undo-changes conj (make-change
|
||||
(update :undo-changes d/preconj (make-change
|
||||
container
|
||||
{:type :mov-objects
|
||||
:parent-id (:parent-id shape)
|
||||
|
@ -1114,7 +1114,7 @@
|
|||
:operations
|
||||
[{:type :set-touched
|
||||
:touched new-touched}]}))
|
||||
(update :undo-changes conj (make-change
|
||||
(update :undo-changes d/preconj (make-change
|
||||
container
|
||||
{:type :mod-obj
|
||||
:id (:id dest-shape)
|
||||
|
@ -1139,7 +1139,7 @@
|
|||
:operations
|
||||
[{:type :set-remote-synced
|
||||
:remote-synced? remote-synced?}]}))
|
||||
(update :undo-changes conj (make-change
|
||||
(update :undo-changes d/preconj (make-change
|
||||
container
|
||||
{:type :mod-obj
|
||||
:id (:id shape)
|
||||
|
@ -1191,7 +1191,7 @@
|
|||
container
|
||||
{:type :reg-objects
|
||||
:shapes all-parents}))
|
||||
(update :undo-changes conj (make-change
|
||||
(update :undo-changes d/preconj (make-change
|
||||
container
|
||||
{:type :mod-obj
|
||||
:id (:id dest-shape)
|
||||
|
@ -1222,7 +1222,7 @@
|
|||
uoperations)
|
||||
(recur (next attrs)
|
||||
(conj roperations roperation)
|
||||
(conj uoperations uoperation)))))))))
|
||||
(d/preconj uoperations uoperation)))))))))
|
||||
|
||||
(defn- reposition-shape
|
||||
[shape origin-root dest-root]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue