🐛 Fix undo on page relocate/sorting.

This commit is contained in:
Andrey Antukh 2021-11-24 12:37:55 +01:00 committed by Andrés Moya
parent c4947d3737
commit e7b4010eba
9 changed files with 89 additions and 33 deletions

View file

@ -81,8 +81,6 @@
(when-not (contains? ids ctid)
(swap! storage dissoc ::current-team-id)))))))
(defn fetch-teams
[]
(ptk/reify ::fetch-teams

View file

@ -14,6 +14,7 @@
[app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.common.pages :as cp]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.pages.spec :as spec]
[app.common.spec :as us]
@ -350,16 +351,16 @@
;; TODO: properly handle positioning on undo.
;; TODO: for some reason, the page-id here in some circumstances is `nil`
(defn delete-page
[id]
(ptk/reify ::delete-page
ptk/WatchEvent
(watch [it state _]
(let [page (get-in state [:workspace-data :pages-index id])
rchg {:type :del-page
:id id}
uchg {:type :add-page
:page page}]
rchg {:type :del-page :id id}
uchg {:type :add-page :page page}]
(rx/of (dch/commit-changes {:redo-changes [rchg]
:undo-changes [uchg]
:origin it})
@ -1114,17 +1115,11 @@
(ptk/reify ::relocate-pages
ptk/WatchEvent
(watch [it state _]
(let [cidx (-> (get-in state [:workspace-data :pages])
(d/index-of id))
rchg {:type :mov-page
:id id
:index index}
uchg {:type :mov-page
:id id
:index cidx}]
(rx/of (dch/commit-changes {:redo-changes [rchg]
:undo-changes [uchg]
:origin it}))))))
(let [prev-index (-> (get-in state [:workspace-data :pages])
(d/index-of id))
changes (-> (pcb/empty-changes it id)
(pcb/move-page index prev-index))]
(rx/of (dch/commit-changes changes))))))
;; --- Shape / Selection Alignment and Distribution

View file

@ -114,20 +114,20 @@
:changes changes}))))
(defn commit-changes
[{:keys [redo-changes undo-changes origin save-undo? file-id]
:or {save-undo? true}}]
[{:keys [redo-changes undo-changes origin save-undo? file-id] :or {save-undo? true}}]
(log/debug :msg "commit-changes"
:js/redo-changes redo-changes
:js/undo-changes undo-changes)
(let [error (volatile! nil)
strace (.-stack (ex-info "" {}))]
(let [error (volatile! nil)]
(ptk/reify ::commit-changes
cljs.core/IDeref
(-deref [_]
{:file-id file-id
:hint-events @st/last-events
:hint-origin (ptk/type origin)
:hint-strace strace
:changes redo-changes})
ptk/UpdateEvent
@ -135,7 +135,6 @@
(let [current-file-id (get state :current-file-id)
file-id (or file-id current-file-id)
path (if (= file-id current-file-id)
[:workspace-data]
[:workspace-libraries file-id :data])]
(try

View file

@ -70,7 +70,8 @@
(accumulate-undo-entry state entry)
(add-undo-entry state entry)))))
(defonce empty-tx {:undo-changes [] :redo-changes []})
(def empty-tx
{:undo-changes [] :redo-changes []})
(defn start-undo-transaction []
(ptk/reify ::start-undo-transaction

View file

@ -82,10 +82,9 @@
on-drop
(mf/use-callback
(mf/deps id)
(mf/deps id index)
(fn [side {:keys [id] :as data}]
(let [index (if (= :bot side) (inc index) index)]
(st/emit! (dw/relocate-page id index)))))
(st/emit! (dw/relocate-page id index))))
on-duplicate
(fn [_]