From 1f86f47c3deaa9d9215f9d62e5b8c962aac939af Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Sun, 15 Dec 2024 20:58:03 +0800 Subject: [PATCH] fix: CTRL+z on config files goes back to previous page fixed https://github.com/logseq/db-test/issues/169 --- src/main/frontend/handler/history.cljs | 68 +++++++++++++------------- src/main/frontend/state.cljs | 2 +- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/main/frontend/handler/history.cljs b/src/main/frontend/handler/history.cljs index 9ee0116b9d1..d85e80f6be7 100644 --- a/src/main/frontend/handler/history.cljs +++ b/src/main/frontend/handler/history.cljs @@ -43,42 +43,44 @@ (let [*last-request (atom nil)] (defn- undo-aux! [e] - (state/set-state! :editor/op :undo) - (p/do! - @*last-request - (when-let [repo (state/get-current-repo)] - (let [current-page-uuid-str (some->> (page-util/get-latest-edit-page-id) - db/entity - :block/uuid - str)] - (when (db-transact/request-finished?) - (util/stop e) - (p/do! - (state/set-state! [:editor/last-replace-ref-content-tx repo] nil) - (editor/save-current-block!) - (state/clear-editor-action!) - (let [^js worker @state/*db-worker] - (reset! *last-request (.undo worker repo current-page-uuid-str)) - (p/let [result @*last-request] - (restore-cursor-and-state! result)))))))))) + (when-not (:editor/code-block-context @state/state) + (state/set-state! :editor/op :undo) + (p/do! + @*last-request + (when-let [repo (state/get-current-repo)] + (let [current-page-uuid-str (some->> (page-util/get-latest-edit-page-id) + db/entity + :block/uuid + str)] + (when (db-transact/request-finished?) + (util/stop e) + (p/do! + (state/set-state! [:editor/last-replace-ref-content-tx repo] nil) + (editor/save-current-block!) + (state/clear-editor-action!) + (let [^js worker @state/*db-worker] + (reset! *last-request (.undo worker repo current-page-uuid-str)) + (p/let [result @*last-request] + (restore-cursor-and-state! result))))))))))) (defonce undo! (debounce undo-aux! 20)) (let [*last-request (atom nil)] (defn- redo-aux! [e] - (state/set-state! :editor/op :redo) - (p/do! - @*last-request - (when-let [repo (state/get-current-repo)] - (let [current-page-uuid-str (some->> (page-util/get-latest-edit-page-id) - db/entity - :block/uuid - str)] - (when (db-transact/request-finished?) - (util/stop e) - (state/clear-editor-action!) - (let [^js worker @state/*db-worker] - (reset! *last-request (.redo worker repo current-page-uuid-str)) - (p/let [result @*last-request] - (restore-cursor-and-state! result))))))))) + (when-not (:editor/code-block-context @state/state) + (state/set-state! :editor/op :redo) + (p/do! + @*last-request + (when-let [repo (state/get-current-repo)] + (let [current-page-uuid-str (some->> (page-util/get-latest-edit-page-id) + db/entity + :block/uuid + str)] + (when (db-transact/request-finished?) + (util/stop e) + (state/clear-editor-action!) + (let [^js worker @state/*db-worker] + (reset! *last-request (.redo worker repo current-page-uuid-str)) + (p/let [result @*last-request] + (restore-cursor-and-state! result)))))))))) (defonce redo! (debounce redo-aux! 20)) diff --git a/src/main/frontend/state.cljs b/src/main/frontend/state.cljs index 93a62c13114..0cdeab30ae7 100644 --- a/src/main/frontend/state.cljs +++ b/src/main/frontend/state.cljs @@ -1363,7 +1363,7 @@ Similar to re-frame subscriptions" (defn into-code-editor-mode! [] (set-state! :editor/cursor-range nil) - (swap! state merge {:editor/code-mode? true})) + (swap! state assoc :editor/code-mode? true)) (defn set-editor-last-pos! [new-pos]