diff --git a/frontend/src/app/main/data/changes.cljs b/frontend/src/app/main/data/changes.cljs index 303abc14ec..d73e22a1e2 100644 --- a/frontend/src/app/main/data/changes.cljs +++ b/frontend/src/app/main/data/changes.cljs @@ -42,6 +42,15 @@ (def changes-applied? (ptk/type? ::changes-applied)) +(def changes-recorded? + (ptk/type? ::changes-recorded)) + +(defn changes-recorded + "The commit has applied and its undo entry has been recorded. Derived + edits can now follow it without reversing transaction history." + [transition] + (ptk/data-event ::changes-recorded transition)) + (defn- fix-page-id "For events that modifies the page, page-id does not comes as a property so we assign it from the `id` property." diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 850fa46929..22fb8197ac 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -508,19 +508,23 @@ (rx/take-until stopper-s))) (->> stream - (rx/filter dch/commit?) + (rx/filter dch/changes-applied?) (rx/map deref) (rx/mapcat - (fn [{:keys [file-id save-undo? undo-changes redo-changes undo-group tags stack-undo? selected-before translation?]}] - (if (and save-undo? (seq undo-changes)) - (let [entry {:undo-changes (mapv #(assoc % ::dwu/file-id file-id) undo-changes) - :redo-changes (mapv #(assoc % ::dwu/file-id file-id) redo-changes) - :undo-group undo-group - :tags tags - :selected-before selected-before - :translation (boolean translation?)}] - (rx/of (dwu/append-undo entry stack-undo?))) - (rx/empty)))))) + (fn [{:keys [commit] :as transition}] + (let [{:keys [file-id save-undo? undo-changes redo-changes undo-group + tags stack-undo? selected-before translation?]} commit] + (rx/concat + (if (and save-undo? (seq undo-changes)) + (let [entry {:undo-changes (mapv #(assoc % ::dwu/file-id file-id) undo-changes) + :redo-changes (mapv #(assoc % ::dwu/file-id file-id) redo-changes) + :undo-group undo-group + :tags tags + :selected-before selected-before + :translation (boolean translation?)}] + (rx/of (dwu/append-undo entry stack-undo?))) + (rx/empty)) + (rx/of (dch/changes-recorded transition)))))))) (rx/take-until stopper-s))))))) (defn initialize-workspace diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 62995acf84..7bf928e44f 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -1635,7 +1635,7 @@ local-commits-s (->> stream - (rx/filter dch/changes-applied?) + (rx/filter dch/changes-recorded?) (rx/map deref) (rx/filter #(= :local (get-in % [:commit :source]))) ;; Keep waits pending while component changes are checked. diff --git a/frontend/test/frontend_tests/composable_tests/generated_test.cljs b/frontend/test/frontend_tests/composable_tests/generated_test.cljs index d21402a152..a64bca9ee6 100644 --- a/frontend/test/frontend_tests/composable_tests/generated_test.cljs +++ b/frontend/test/frontend_tests/composable_tests/generated_test.cljs @@ -86,3 +86,6 @@ (t/deftest ^:async nested-text-rotation-shrunk-regression (await (replay {:world [2 0 {:text true}] :ops [[:nest 0] [:detach 0] [:rotate 0]]}))) + +(t/deftest ^:async nesting-restores-default-constraints-on-undo + (await (replay {:world [2 0] :ops [[:nest 0]]}))) diff --git a/frontend/test/frontend_tests/data/workspace_heal_undo_test.cljs b/frontend/test/frontend_tests/data/workspace_heal_undo_test.cljs index 1dc4934d35..1ff6c97ec5 100644 --- a/frontend/test/frontend_tests/data/workspace_heal_undo_test.cljs +++ b/frontend/test/frontend_tests/data/workspace_heal_undo_test.cljs @@ -17,6 +17,7 @@ [app.common.test-helpers.shapes :as cths] [app.main.data.changes :as dch] [app.main.data.helpers :as dsh] + [app.main.data.workspace :as dw] [app.main.data.workspace.libraries :as dwl] [app.main.data.workspace.pages :as dwpg] [app.main.data.workspace.shape-layout :as dwsl] @@ -413,7 +414,9 @@ ;; sync-file clears frame thumbnails on a timer that outlives the test dwth/clear-thumbnail (mock/stub (constantly nil))} - (ptk/emit! store (tohs/watch-undo-stack)) + ;; The edit watchers record the undo history and pass each commit on + ;; to the component watcher + (ptk/emit! store (dw/initialize-edit-watchers)) (ptk/emit! store (dwl/watch-component-changes)) ;; The user edit, synced to the copy @@ -440,5 +443,7 @@ (t/is (= copy-0 (before copy-id)) "the copy is back to its size and opacity") - (ptk/emit! store (dwpg/finalize-page (:id file) page-id)) + (ptk/emit! store + (dw/finalize-edit-watchers) + (dwpg/finalize-page (:id file) page-id)) (await (async/settle))))))