0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-12 18:18:24 -05:00

🐛 Fix grouping of undo transactions

This commit is contained in:
Andrés Moya 2023-05-22 10:57:55 +02:00
parent f73d7111b4
commit 9d5b59e9bb
4 changed files with 17 additions and 6 deletions

View file

@ -172,10 +172,6 @@
[{:keys [redo-changes undo-changes
origin save-undo? file-id undo-group tags stack-undo?]
:or {save-undo? true stack-undo? false tags #{} undo-group (uuid/next)}}]
(log/debug :msg "commit-changes"
:js/undo-group (str undo-group)
:js/redo-changes redo-changes
:js/undo-changes undo-changes)
(let [error (volatile! nil)
page-id (:current-page-id @st/state)
frames (changed-frames redo-changes (wsh/lookup-page-objects @st/state))]
@ -195,6 +191,10 @@
ptk/UpdateEvent
(update [_ state]
(log/info :msg "commit-changes"
:js/undo-group (str undo-group)
:js/redo-changes redo-changes
:js/undo-changes undo-changes)
(let [current-file-id (get state :current-file-id)
file-id (or file-id current-file-id)
path (if (= file-id current-file-id)

View file

@ -890,7 +890,8 @@
changes)]
(when (and (d/not-empty? components-changed) save-undo?)
(log/info :msg "DETECTED COMPONENTS CHANGED"
:ids (map str components-changed))
:ids (map str components-changed)
:undo-group undo-group)
(run! st/emit!
(map #(update-component-sync % (:id old-data) undo-group)
components-changed)))))]

View file

@ -376,6 +376,7 @@
(some? id)
(d/toggle-selection id shift?))]
;; Take the first mouse position and start a move or a duplicate
(when (or (d/not-empty? selected) (some? id))
(->> ms/mouse-position
(rx/map #(gpt/to-vec initial %))

View file

@ -8,10 +8,14 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.logging :as log]
[app.common.pages.changes :as cpc]
[app.common.schema :as sm]
[potok.core :as ptk]))
;; Change this to :info :debug or :trace to debug this module
(log/set-level! :warn)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Undo / Redo
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -74,7 +78,9 @@
(-> state
(update-in [:workspace-undo :transaction :undo-changes] #(into undo-changes %))
(update-in [:workspace-undo :transaction :redo-changes] #(into % redo-changes))
(assoc-in [:workspace-undo :transaction :undo-group] undo-group)
(cond->
(nil? (get-in state [:workspace-undo :transaction :undo-group]))
(assoc-in [:workspace-undo :transaction :undo-group] undo-group))
(assoc-in [:workspace-undo :transaction :tags] tags)))
(defn append-undo
@ -107,6 +113,7 @@
(ptk/reify ::start-undo-transaction
ptk/UpdateEvent
(update [_ state]
(log/info :msg "start-undo-transaction")
;; We commit the old transaction before starting the new one
(let [current-tx (get-in state [:workspace-undo :transaction])
pending-tx (get-in state [:workspace-undo :transactions-pending])]
@ -119,12 +126,14 @@
(ptk/reify ::discard-undo-transaction
ptk/UpdateEvent
(update [_ state]
(log/info :msg "discard-undo-transaction")
(update state :workspace-undo dissoc :transaction :transactions-pending))))
(defn commit-undo-transaction [id]
(ptk/reify ::commit-undo-transaction
ptk/UpdateEvent
(update [_ state]
(log/info :msg "commit-undo-transaction")
(let [state (update-in state [:workspace-undo :transactions-pending] disj id)]
(if (empty? (get-in state [:workspace-undo :transactions-pending]))
(-> state