mirror of
https://github.com/penpot/penpot.git
synced 2025-05-30 07:36:13 +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
|
(defn preconj
|
||||||
[coll elem]
|
[coll elem]
|
||||||
(assert (vector? coll))
|
(assert (or (vector? coll) (nil? coll)))
|
||||||
(into [elem] coll))
|
(into [elem] coll))
|
||||||
|
|
||||||
(defn enumerate
|
(defn enumerate
|
||||||
|
|
|
@ -124,35 +124,35 @@
|
||||||
[changes id name]
|
[changes id name]
|
||||||
(-> changes
|
(-> changes
|
||||||
(update :redo-changes conj {:type :add-page :id id :name name})
|
(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)))
|
(apply-changes-local)))
|
||||||
|
|
||||||
(defn add-page
|
(defn add-page
|
||||||
[changes id page]
|
[changes id page]
|
||||||
(-> changes
|
(-> changes
|
||||||
(update :redo-changes conj {:type :add-page :id id :page page})
|
(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)))
|
(apply-changes-local)))
|
||||||
|
|
||||||
(defn mod-page
|
(defn mod-page
|
||||||
[changes page new-name]
|
[changes page new-name]
|
||||||
(-> changes
|
(-> changes
|
||||||
(update :redo-changes conj {:type :mod-page :id (:id page) :name new-name})
|
(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)))
|
(apply-changes-local)))
|
||||||
|
|
||||||
(defn del-page
|
(defn del-page
|
||||||
[changes page]
|
[changes page]
|
||||||
(-> changes
|
(-> changes
|
||||||
(update :redo-changes conj {:type :del-page :id (:id page)})
|
(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)))
|
(apply-changes-local)))
|
||||||
|
|
||||||
(defn move-page
|
(defn move-page
|
||||||
[changes page-id index prev-index]
|
[changes page-id index prev-index]
|
||||||
(-> changes
|
(-> changes
|
||||||
(update :redo-changes conj {:type :mov-page :id page-id :index index})
|
(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)))
|
(apply-changes-local)))
|
||||||
|
|
||||||
(defn set-page-option
|
(defn set-page-option
|
||||||
|
@ -167,10 +167,10 @@
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
:option option-key
|
:option option-key
|
||||||
:value option-val})
|
:value option-val})
|
||||||
(update :undo-changes conj {:type :set-option
|
(update :undo-changes d/preconj {:type :set-option
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
:option option-key
|
:option option-key
|
||||||
:value old-val})
|
:value old-val})
|
||||||
(apply-changes-local))))
|
(apply-changes-local))))
|
||||||
|
|
||||||
(defn update-page-option
|
(defn update-page-option
|
||||||
|
@ -186,10 +186,10 @@
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
:option option-key
|
:option option-key
|
||||||
:value new-val})
|
:value new-val})
|
||||||
(update :undo-changes conj {:type :set-option
|
(update :undo-changes d/preconj {:type :set-option
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
:option option-key
|
:option option-key
|
||||||
:value old-val})
|
:value old-val})
|
||||||
(apply-changes-local))))
|
(apply-changes-local))))
|
||||||
|
|
||||||
;; Shape tree changes
|
;; Shape tree changes
|
||||||
|
@ -280,8 +280,8 @@
|
||||||
(update :rops conj {:type :set :attr attr :val new-val
|
(update :rops conj {:type :set :attr attr :val new-val
|
||||||
:ignore-geometry ignore-geometry?
|
:ignore-geometry ignore-geometry?
|
||||||
:ignore-touched ignore-touched})
|
: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})))))
|
:ignore-touched true})))))
|
||||||
|
|
||||||
update-shape
|
update-shape
|
||||||
(fn [changes id]
|
(fn [changes id]
|
||||||
|
@ -297,7 +297,7 @@
|
||||||
|
|
||||||
uops (cond-> uops
|
uops (cond-> uops
|
||||||
(seq 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
|
change (cond-> {:type :mod-obj
|
||||||
:id id}
|
:id id}
|
||||||
|
@ -404,7 +404,7 @@
|
||||||
operations
|
operations
|
||||||
(-> operations
|
(-> operations
|
||||||
(update :rops conj {:type :set :attr attr :val new-val :ignore-touched true})
|
(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
|
resize-parent
|
||||||
(fn [changes parent]
|
(fn [changes parent]
|
||||||
|
@ -452,7 +452,7 @@
|
||||||
[changes color]
|
[changes color]
|
||||||
(-> changes
|
(-> changes
|
||||||
(update :redo-changes conj {:type :add-color :color color})
|
(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)))
|
(apply-changes-local)))
|
||||||
|
|
||||||
(defn update-color
|
(defn update-color
|
||||||
|
@ -462,7 +462,7 @@
|
||||||
prev-color (get-in library-data [:colors (:id color)])]
|
prev-color (get-in library-data [:colors (:id color)])]
|
||||||
(-> changes
|
(-> changes
|
||||||
(update :redo-changes conj {:type :mod-color :color color})
|
(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))))
|
(apply-changes-local))))
|
||||||
|
|
||||||
(defn delete-color
|
(defn delete-color
|
||||||
|
@ -472,14 +472,14 @@
|
||||||
prev-color (get-in library-data [:colors color-id])]
|
prev-color (get-in library-data [:colors color-id])]
|
||||||
(-> changes
|
(-> changes
|
||||||
(update :redo-changes conj {:type :del-color :id color-id})
|
(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))))
|
(apply-changes-local))))
|
||||||
|
|
||||||
(defn add-media
|
(defn add-media
|
||||||
[changes object]
|
[changes object]
|
||||||
(-> changes
|
(-> changes
|
||||||
(update :redo-changes conj {:type :add-media :object object})
|
(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)))
|
(apply-changes-local)))
|
||||||
|
|
||||||
(defn update-media
|
(defn update-media
|
||||||
|
@ -489,7 +489,7 @@
|
||||||
prev-object (get-in library-data [:media (:id object)])]
|
prev-object (get-in library-data [:media (:id object)])]
|
||||||
(-> changes
|
(-> changes
|
||||||
(update :redo-changes conj {:type :mod-media :object object})
|
(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))))
|
(apply-changes-local))))
|
||||||
|
|
||||||
(defn delete-media
|
(defn delete-media
|
||||||
|
@ -499,14 +499,14 @@
|
||||||
prev-object (get-in library-data [:media id])]
|
prev-object (get-in library-data [:media id])]
|
||||||
(-> changes
|
(-> changes
|
||||||
(update :redo-changes conj {:type :del-media :id id})
|
(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))))
|
(apply-changes-local))))
|
||||||
|
|
||||||
(defn add-typography
|
(defn add-typography
|
||||||
[changes typography]
|
[changes typography]
|
||||||
(-> changes
|
(-> changes
|
||||||
(update :redo-changes conj {:type :add-typography :typography typography})
|
(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)))
|
(apply-changes-local)))
|
||||||
|
|
||||||
(defn update-typography
|
(defn update-typography
|
||||||
|
@ -516,7 +516,7 @@
|
||||||
prev-typography (get-in library-data [:typographies (:id typography)])]
|
prev-typography (get-in library-data [:typographies (:id typography)])]
|
||||||
(-> changes
|
(-> changes
|
||||||
(update :redo-changes conj {:type :mod-typography :typography typography})
|
(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))))
|
(apply-changes-local))))
|
||||||
|
|
||||||
(defn delete-typography
|
(defn delete-typography
|
||||||
|
@ -526,7 +526,7 @@
|
||||||
prev-typography (get-in library-data [:typographies typography-id])]
|
prev-typography (get-in library-data [:typographies typography-id])]
|
||||||
(-> changes
|
(-> changes
|
||||||
(update :redo-changes conj {:type :del-typography :id typography-id})
|
(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))))
|
(apply-changes-local))))
|
||||||
|
|
||||||
(defn add-component
|
(defn add-component
|
||||||
|
@ -569,8 +569,8 @@
|
||||||
(update :undo-changes
|
(update :undo-changes
|
||||||
(fn [undo-changes]
|
(fn [undo-changes]
|
||||||
(-> undo-changes
|
(-> undo-changes
|
||||||
(conj {:type :del-component
|
(d/preconj {:type :del-component
|
||||||
:id id})
|
:id id})
|
||||||
(into (comp (map :id)
|
(into (comp (map :id)
|
||||||
(map lookupf)
|
(map lookupf)
|
||||||
(map mk-change))
|
(map mk-change))
|
||||||
|
@ -590,11 +590,11 @@
|
||||||
:name (:name new-component)
|
:name (:name new-component)
|
||||||
:path (:path new-component)
|
:path (:path new-component)
|
||||||
:objects (:objects new-component)})
|
:objects (:objects new-component)})
|
||||||
(update :undo-changes conj {:type :mod-component
|
(update :undo-changes d/preconj {:type :mod-component
|
||||||
:id id
|
:id id
|
||||||
:name (:name prev-component)
|
:name (:name prev-component)
|
||||||
:path (:path prev-component)
|
:path (:path prev-component)
|
||||||
:objects (:objects prev-component)}))
|
:objects (:objects prev-component)}))
|
||||||
changes)))
|
changes)))
|
||||||
|
|
||||||
(defn delete-component
|
(defn delete-component
|
||||||
|
@ -605,9 +605,9 @@
|
||||||
(-> changes
|
(-> changes
|
||||||
(update :redo-changes conj {:type :del-component
|
(update :redo-changes conj {:type :del-component
|
||||||
:id id})
|
:id id})
|
||||||
(update :undo-changes conj {:type :add-component
|
(update :undo-changes d/preconj {:type :add-component
|
||||||
:id id
|
:id id
|
||||||
:name (:name prev-component)
|
:name (:name prev-component)
|
||||||
:path (:path prev-component)
|
:path (:path prev-component)
|
||||||
:shapes (vals (:objects prev-component))}))))
|
:shapes (vals (:objects prev-component))}))))
|
||||||
|
|
||||||
|
|
|
@ -357,13 +357,13 @@
|
||||||
:operations [{:type :set
|
:operations [{:type :set
|
||||||
:attr :content
|
:attr :content
|
||||||
:val new-content}]}))
|
:val new-content}]}))
|
||||||
(update :undo-changes conj (make-change
|
(update :undo-changes d/preconj (make-change
|
||||||
container
|
container
|
||||||
{:type :mod-obj
|
{:type :mod-obj
|
||||||
:id (:id shape)
|
:id (:id shape)
|
||||||
:operations [{:type :set
|
:operations [{:type :set
|
||||||
:attr :content
|
:attr :content
|
||||||
:val old-content}]})))]
|
:val old-content}]})))]
|
||||||
(if (= new-content old-content)
|
(if (= new-content old-content)
|
||||||
changes
|
changes
|
||||||
changes')))
|
changes')))
|
||||||
|
@ -915,7 +915,7 @@
|
||||||
(assoc :frame-id (:frame-id shape')))))))
|
(assoc :frame-id (:frame-id shape')))))))
|
||||||
|
|
||||||
del-obj-change (fn [changes shape']
|
del-obj-change (fn [changes shape']
|
||||||
(update changes :undo-changes conj
|
(update changes :undo-changes d/preconj
|
||||||
(make-change
|
(make-change
|
||||||
container
|
container
|
||||||
{:type :del-obj
|
{:type :del-obj
|
||||||
|
@ -994,7 +994,7 @@
|
||||||
:val (:touched shape')}]}))
|
:val (:touched shape')}]}))
|
||||||
|
|
||||||
del-obj-change (fn [changes shape']
|
del-obj-change (fn [changes shape']
|
||||||
(update changes :undo-changes conj
|
(update changes :undo-changes d/preconj
|
||||||
{:type :del-obj
|
{:type :del-obj
|
||||||
:id (:id shape')
|
:id (:id shape')
|
||||||
:page-id (:id page)
|
:page-id (:id page)
|
||||||
|
@ -1021,7 +1021,7 @@
|
||||||
|
|
||||||
add-undo-change (fn [changes id]
|
add-undo-change (fn [changes id]
|
||||||
(let [shape' (get objects id)]
|
(let [shape' (get objects id)]
|
||||||
(update changes :undo-changes conj
|
(update changes :undo-changes d/preconj
|
||||||
(make-change
|
(make-change
|
||||||
container
|
container
|
||||||
(as-> {:type :add-obj
|
(as-> {:type :add-obj
|
||||||
|
@ -1073,13 +1073,13 @@
|
||||||
:shapes [(:id shape)]
|
:shapes [(:id shape)]
|
||||||
:index index-after
|
:index index-after
|
||||||
:ignore-touched true}))
|
:ignore-touched true}))
|
||||||
(update :undo-changes conj (make-change
|
(update :undo-changes d/preconj (make-change
|
||||||
container
|
container
|
||||||
{:type :mov-objects
|
{:type :mov-objects
|
||||||
:parent-id (:parent-id shape)
|
:parent-id (:parent-id shape)
|
||||||
:shapes [(:id shape)]
|
:shapes [(:id shape)]
|
||||||
:index index-before
|
:index index-before
|
||||||
:ignore-touched true})))]
|
:ignore-touched true})))]
|
||||||
|
|
||||||
(if (and (cph/touched-group? parent :shapes-group) omit-touched?)
|
(if (and (cph/touched-group? parent :shapes-group) omit-touched?)
|
||||||
changes
|
changes
|
||||||
|
@ -1114,13 +1114,13 @@
|
||||||
:operations
|
:operations
|
||||||
[{:type :set-touched
|
[{:type :set-touched
|
||||||
:touched new-touched}]}))
|
:touched new-touched}]}))
|
||||||
(update :undo-changes conj (make-change
|
(update :undo-changes d/preconj (make-change
|
||||||
container
|
container
|
||||||
{:type :mod-obj
|
{:type :mod-obj
|
||||||
:id (:id dest-shape)
|
:id (:id dest-shape)
|
||||||
:operations
|
:operations
|
||||||
[{:type :set-touched
|
[{:type :set-touched
|
||||||
:touched (:touched dest-shape)}]})))))))
|
:touched (:touched dest-shape)}]})))))))
|
||||||
|
|
||||||
(defn- change-remote-synced
|
(defn- change-remote-synced
|
||||||
[changes shape container remote-synced?]
|
[changes shape container remote-synced?]
|
||||||
|
@ -1139,13 +1139,13 @@
|
||||||
:operations
|
:operations
|
||||||
[{:type :set-remote-synced
|
[{:type :set-remote-synced
|
||||||
:remote-synced? remote-synced?}]}))
|
:remote-synced? remote-synced?}]}))
|
||||||
(update :undo-changes conj (make-change
|
(update :undo-changes d/preconj (make-change
|
||||||
container
|
container
|
||||||
{:type :mod-obj
|
{:type :mod-obj
|
||||||
:id (:id shape)
|
:id (:id shape)
|
||||||
:operations
|
:operations
|
||||||
[{:type :set-remote-synced
|
[{:type :set-remote-synced
|
||||||
:remote-synced? (:remote-synced? shape)}]}))))))
|
:remote-synced? (:remote-synced? shape)}]}))))))
|
||||||
|
|
||||||
(defn- update-attrs
|
(defn- update-attrs
|
||||||
"The main function that implements the attribute sync algorithm. Copy
|
"The main function that implements the attribute sync algorithm. Copy
|
||||||
|
@ -1191,11 +1191,11 @@
|
||||||
container
|
container
|
||||||
{:type :reg-objects
|
{:type :reg-objects
|
||||||
:shapes all-parents}))
|
:shapes all-parents}))
|
||||||
(update :undo-changes conj (make-change
|
(update :undo-changes d/preconj (make-change
|
||||||
container
|
container
|
||||||
{:type :mod-obj
|
{:type :mod-obj
|
||||||
:id (:id dest-shape)
|
:id (:id dest-shape)
|
||||||
:operations uoperations}))
|
:operations uoperations}))
|
||||||
(update :undo-changes conj (make-change
|
(update :undo-changes conj (make-change
|
||||||
container
|
container
|
||||||
{:type :reg-objects
|
{:type :reg-objects
|
||||||
|
@ -1222,7 +1222,7 @@
|
||||||
uoperations)
|
uoperations)
|
||||||
(recur (next attrs)
|
(recur (next attrs)
|
||||||
(conj roperations roperation)
|
(conj roperations roperation)
|
||||||
(conj uoperations uoperation)))))))))
|
(d/preconj uoperations uoperation)))))))))
|
||||||
|
|
||||||
(defn- reposition-shape
|
(defn- reposition-shape
|
||||||
[shape origin-root dest-root]
|
[shape origin-root dest-root]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue