🐛 Fix some undo while actions in flex

This commit is contained in:
Eva 2023-01-11 18:48:09 +01:00 committed by Alonso Torres
parent 4f81f9636a
commit 8df861faaa
6 changed files with 60 additions and 31 deletions

View file

@ -812,11 +812,14 @@
layouts-to-update layouts-to-update
(into #{} (into #{}
(filter (partial ctl/layout? objects)) (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) (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 (defn relocate-selected-shapes
[parent-id to-index] [parent-id to-index]
@ -1558,11 +1561,14 @@
(filter #(= (:type %) :add-obj)) (filter #(= (:type %) :add-obj))
(filter #(selected (:old-id %))) (filter #(selected (:old-id %)))
(map #(get-in % [:obj :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) (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/reify ::paste-shape
ptk/WatchEvent ptk/WatchEvent

View file

@ -16,6 +16,7 @@
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.selection :as dws] [app.main.data.workspace.selection :as dws]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
[app.main.data.workspace.undo :as dwu]
[beicon.core :as rx] [beicon.core :as rx]
[potok.core :as ptk])) [potok.core :as ptk]))
@ -188,10 +189,13 @@
changes {:redo-changes (vec (mapcat :redo-changes changes-list)) changes {:redo-changes (vec (mapcat :redo-changes changes-list))
:undo-changes (vec (mapcat :undo-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) (rx/of (dwu/start-undo-transaction undo-id)
(ptk/data-event :layout/update parents)))))) (dch/commit-changes changes)
(ptk/data-event :layout/update parents)
(dwu/commit-undo-transaction undo-id))))))
(def mask-group (def mask-group
(ptk/reify ::mask-group (ptk/reify ::mask-group

View file

@ -254,8 +254,11 @@
(ptk/reify ::update-layout (ptk/reify ::update-layout
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
(rx/of (dwc/update-shapes ids #(d/deep-merge % changes)) (let [undo-id (js/Symbol)]
(ptk/data-event :layout/update ids))))) (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 (defn update-layout-child
[ids changes] [ids changes]
@ -264,6 +267,9 @@
(watch [_ state _] (watch [_ state _]
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
parent-ids (->> ids (map #(cph/get-parent-id objects %))) parent-ids (->> ids (map #(cph/get-parent-id objects %)))
layout-ids (->> ids (filter (comp ctl/layout? (d/getf objects))))] layout-ids (->> ids (filter (comp ctl/layout? (d/getf objects))))
(rx/of (dwc/update-shapes ids #(d/deep-merge (or % {}) changes)) undo-id (js/Symbol)]
(ptk/data-event :layout/update (d/concat-vec layout-ids parent-ids))))))) (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))))))

View file

@ -99,17 +99,20 @@
changes (-> (pcb/empty-changes it page-id) changes (-> (pcb/empty-changes it page-id)
(pcb/with-objects objects) (pcb/with-objects objects)
(cond-> (some? (:index (meta attrs))) (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))) (cond-> (nil? (:index (meta attrs)))
(pcb/add-object shape)) (pcb/add-object shape))
(cond-> (some? (:parent-id attrs)) (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/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)]) (ptk/data-event :layout/update [(:parent-id shape)])
(when-not no-select? (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)) (when (= :text (:type attrs))
(->> (rx/of (dwe/start-edition-mode id)) (->> (rx/of (dwe/start-edition-mode id))
(rx/observe-on :async))))))))) (rx/observe-on :async)))))))))
@ -307,12 +310,15 @@
(cond-> (seq starting-flows) (cond-> (seq starting-flows)
(pcb/update-page-option :flows (fn [flows] (pcb/update-page-option :flows (fn [flows]
(->> (map :id starting-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) (ptk/data-event :layout/update all-parents)
(dch/commit-changes changes) (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 (defn create-and-add-shape
[type frame-x frame-y data] [type frame-x frame-y data]

View file

@ -323,7 +323,8 @@
(ptk/reify ::resize-text (ptk/reify ::resize-text
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [shape (wsh/lookup-shape state id)] (let [shape (wsh/lookup-shape state id)
undo-id (js/Symbol)]
(letfn [(update-fn [shape] (letfn [(update-fn [shape]
(let [{:keys [selrect grow-type]} shape (let [{:keys [selrect grow-type]} shape
{shape-width :width shape-height :height} selrect {shape-width :width shape-height :height} selrect
@ -335,17 +336,19 @@
shape shape
(cond-> shape (cond-> shape
(and (not-changed? shape-height new-height) (and (not-changed? shape-height new-height)
(or (= grow-type :auto-height) (= grow-type :auto-width))) (or (= grow-type :auto-height) (= grow-type :auto-width)))
(gsh/transform-shape (ctm/change-dimensions-modifiers shape :height new-height {:ignore-lock? true})))] (gsh/transform-shape (ctm/change-dimensions-modifiers shape :height new-height {:ignore-lock? true})))]
shape))] shape))]
(when (or (and (not-changed? (:width shape) new-width) (= (:grow-type shape) :auto-width)) (when (or (and (not-changed? (:width shape) new-width) (= (:grow-type shape) :auto-width))
(and (not-changed? (:height shape) new-height) (and (not-changed? (:height shape) new-height)
(or (= (:grow-type shape) :auto-height) (= (:grow-type shape) :auto-width)))) (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}) (rx/of (dwu/start-undo-transaction undo-id)
(ptk/data-event :layout/update [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 (defn save-font

View file

@ -570,10 +570,14 @@
index)) index))
changes))) changes)))
(-> (pcb/empty-changes it page-id) (-> (pcb/empty-changes it page-id)
(pcb/with-objects objects))))] (pcb/with-objects objects))))
undo-id (js/Symbol)]
(rx/of (dch/commit-changes changes) (rx/of
(ptk/data-event :layout/update selected)))))) (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 (defn nudge-selected-shapes
"Move shapes a fixed increment in one direction, from a keyboard action." "Move shapes a fixed increment in one direction, from a keyboard action."