From 8df861faaac96183f32cdd33e7afdaebbd56f26d Mon Sep 17 00:00:00 2001 From: Eva Date: Wed, 11 Jan 2023 18:48:09 +0100 Subject: [PATCH] :bug: Fix some undo while actions in flex --- frontend/src/app/main/data/workspace.cljs | 18 ++++++++++----- .../src/app/main/data/workspace/groups.cljs | 10 ++++++--- .../app/main/data/workspace/shape_layout.cljs | 16 +++++++++----- .../src/app/main/data/workspace/shapes.cljs | 22 ++++++++++++------- .../src/app/main/data/workspace/texts.cljs | 15 ++++++++----- .../app/main/data/workspace/transforms.cljs | 10 ++++++--- 6 files changed, 60 insertions(+), 31 deletions(-) diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index e642bd17a..fc55346c9 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -812,11 +812,14 @@ layouts-to-update (into #{} (filter (partial ctl/layout? objects)) - (concat [parent-id] (cph/get-parent-ids objects parent-id)))] + (concat [parent-id] (cph/get-parent-ids objects parent-id))) + undo-id (js/Symbol)] - (rx/of (dch/commit-changes changes) + (rx/of (dwu/start-undo-transaction undo-id) + (dch/commit-changes changes) (dwco/expand-collapse parent-id) - (ptk/data-event :layout/update layouts-to-update)))))) + (ptk/data-event :layout/update layouts-to-update) + (dwu/commit-undo-transaction undo-id)))))) (defn relocate-selected-shapes [parent-id to-index] @@ -1558,11 +1561,14 @@ (filter #(= (:type %) :add-obj)) (filter #(selected (:old-id %))) (map #(get-in % [:obj :id])) - (into (d/ordered-set)))] + (into (d/ordered-set))) + undo-id (js/Symbol)] - (rx/of (dch/commit-changes changes) + (rx/of (dwu/start-undo-transaction undo-id) + (dch/commit-changes changes) (dws/select-shapes selected) - (ptk/data-event :layout/update [frame-id]))))] + (ptk/data-event :layout/update [frame-id]) + (dwu/commit-undo-transaction undo-id))))] (ptk/reify ::paste-shape ptk/WatchEvent diff --git a/frontend/src/app/main/data/workspace/groups.cljs b/frontend/src/app/main/data/workspace/groups.cljs index fde89eb0c..509589ba7 100644 --- a/frontend/src/app/main/data/workspace/groups.cljs +++ b/frontend/src/app/main/data/workspace/groups.cljs @@ -16,6 +16,7 @@ [app.main.data.workspace.changes :as dch] [app.main.data.workspace.selection :as dws] [app.main.data.workspace.state-helpers :as wsh] + [app.main.data.workspace.undo :as dwu] [beicon.core :as rx] [potok.core :as ptk])) @@ -188,10 +189,13 @@ changes {:redo-changes (vec (mapcat :redo-changes changes-list)) :undo-changes (vec (mapcat :undo-changes changes-list)) - :origin it}] + :origin it} + undo-id (js/Symbol)] - (rx/of (dch/commit-changes changes) - (ptk/data-event :layout/update parents)))))) + (rx/of (dwu/start-undo-transaction undo-id) + (dch/commit-changes changes) + (ptk/data-event :layout/update parents) + (dwu/commit-undo-transaction undo-id)))))) (def mask-group (ptk/reify ::mask-group diff --git a/frontend/src/app/main/data/workspace/shape_layout.cljs b/frontend/src/app/main/data/workspace/shape_layout.cljs index 0ebad4a3e..8ca06bd2d 100644 --- a/frontend/src/app/main/data/workspace/shape_layout.cljs +++ b/frontend/src/app/main/data/workspace/shape_layout.cljs @@ -254,8 +254,11 @@ (ptk/reify ::update-layout ptk/WatchEvent (watch [_ _ _] - (rx/of (dwc/update-shapes ids #(d/deep-merge % changes)) - (ptk/data-event :layout/update ids))))) + (let [undo-id (js/Symbol)] + (rx/of (dwu/start-undo-transaction undo-id) + (dwc/update-shapes ids #(d/deep-merge % changes)) + (ptk/data-event :layout/update ids) + (dwu/commit-undo-transaction undo-id)))))) (defn update-layout-child [ids changes] @@ -264,6 +267,9 @@ (watch [_ state _] (let [objects (wsh/lookup-page-objects state) parent-ids (->> ids (map #(cph/get-parent-id objects %))) - layout-ids (->> ids (filter (comp ctl/layout? (d/getf objects))))] - (rx/of (dwc/update-shapes ids #(d/deep-merge (or % {}) changes)) - (ptk/data-event :layout/update (d/concat-vec layout-ids parent-ids))))))) + layout-ids (->> ids (filter (comp ctl/layout? (d/getf objects)))) + undo-id (js/Symbol)] + (rx/of (dwu/start-undo-transaction undo-id) + (dwc/update-shapes ids #(d/deep-merge (or % {}) changes)) + (ptk/data-event :layout/update (d/concat-vec layout-ids parent-ids)) + (dwu/commit-undo-transaction undo-id)))))) diff --git a/frontend/src/app/main/data/workspace/shapes.cljs b/frontend/src/app/main/data/workspace/shapes.cljs index 72b3375f7..94ab70ebd 100644 --- a/frontend/src/app/main/data/workspace/shapes.cljs +++ b/frontend/src/app/main/data/workspace/shapes.cljs @@ -99,17 +99,20 @@ changes (-> (pcb/empty-changes it page-id) (pcb/with-objects objects) (cond-> (some? (:index (meta attrs))) - (pcb/add-object shape {:index (:index (meta attrs))})) + (pcb/add-object shape {:index (:index (meta attrs))})) (cond-> (nil? (:index (meta attrs))) - (pcb/add-object shape)) + (pcb/add-object shape)) (cond-> (some? (:parent-id attrs)) - (pcb/change-parent (:parent-id attrs) [shape])))] + (pcb/change-parent (:parent-id attrs) [shape]))) + undo-id (js/Symbol)] (rx/concat - (rx/of (dch/commit-changes changes) + (rx/of (dwu/start-undo-transaction undo-id) + (dch/commit-changes changes) (ptk/data-event :layout/update [(:parent-id shape)]) (when-not no-select? - (dws/select-shapes (d/ordered-set id)))) + (dws/select-shapes (d/ordered-set id))) + (dwu/commit-undo-transaction undo-id)) (when (= :text (:type attrs)) (->> (rx/of (dwe/start-edition-mode id)) (rx/observe-on :async))))))))) @@ -307,12 +310,15 @@ (cond-> (seq starting-flows) (pcb/update-page-option :flows (fn [flows] (->> (map :id starting-flows) - (reduce ctp/remove-flow flows))))))] + (reduce ctp/remove-flow flows)))))) + undo-id (js/Symbol)] - (rx/of (dc/detach-comment-thread ids) + (rx/of (dwu/start-undo-transaction undo-id) + (dc/detach-comment-thread ids) (ptk/data-event :layout/update all-parents) (dch/commit-changes changes) - (ptk/data-event :layout/update layout-ids)))) + (ptk/data-event :layout/update layout-ids) + (dwu/commit-undo-transaction undo-id)))) (defn create-and-add-shape [type frame-x frame-y data] diff --git a/frontend/src/app/main/data/workspace/texts.cljs b/frontend/src/app/main/data/workspace/texts.cljs index da24c5b22..22759b24b 100644 --- a/frontend/src/app/main/data/workspace/texts.cljs +++ b/frontend/src/app/main/data/workspace/texts.cljs @@ -323,7 +323,8 @@ (ptk/reify ::resize-text ptk/WatchEvent (watch [_ state _] - (let [shape (wsh/lookup-shape state id)] + (let [shape (wsh/lookup-shape state id) + undo-id (js/Symbol)] (letfn [(update-fn [shape] (let [{:keys [selrect grow-type]} shape {shape-width :width shape-height :height} selrect @@ -335,17 +336,19 @@ shape (cond-> shape - (and (not-changed? shape-height new-height) - (or (= grow-type :auto-height) (= grow-type :auto-width))) - (gsh/transform-shape (ctm/change-dimensions-modifiers shape :height new-height {:ignore-lock? true})))] + (and (not-changed? shape-height new-height) + (or (= grow-type :auto-height) (= grow-type :auto-width))) + (gsh/transform-shape (ctm/change-dimensions-modifiers shape :height new-height {:ignore-lock? true})))] shape))] (when (or (and (not-changed? (:width shape) new-width) (= (:grow-type shape) :auto-width)) (and (not-changed? (:height shape) new-height) (or (= (:grow-type shape) :auto-height) (= (:grow-type shape) :auto-width)))) - (rx/of (dch/update-shapes [id] update-fn {:reg-objects? true :save-undo? true}) - (ptk/data-event :layout/update [id])))))))) + (rx/of (dwu/start-undo-transaction undo-id) + (dch/update-shapes [id] update-fn {:reg-objects? true :save-undo? true}) + (ptk/data-event :layout/update [id]) + (dwu/commit-undo-transaction undo-id)))))))) (defn save-font diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index 81e8811c7..ce9798f77 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -570,10 +570,14 @@ index)) changes))) (-> (pcb/empty-changes it page-id) - (pcb/with-objects objects))))] + (pcb/with-objects objects)))) + undo-id (js/Symbol)] - (rx/of (dch/commit-changes changes) - (ptk/data-event :layout/update selected)))))) + (rx/of + (dwu/start-undo-transaction undo-id) + (dch/commit-changes changes) + (ptk/data-event :layout/update selected) + (dwu/commit-undo-transaction undo-id)))))) (defn nudge-selected-shapes "Move shapes a fixed increment in one direction, from a keyboard action."