mirror of
https://github.com/penpot/penpot.git
synced 2025-03-13 16:21:57 -05:00
🐛 Fix some undo while actions in flex
This commit is contained in:
parent
4f81f9636a
commit
8df861faaa
6 changed files with 60 additions and 31 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))))))
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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."
|
||||
|
|
Loading…
Add table
Reference in a new issue