Skip to content

Commit

Permalink
fix: CTRL+z on config files goes back to previous page
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Dec 15, 2024
1 parent 4cb793e commit 1f86f47
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
68 changes: 35 additions & 33 deletions src/main/frontend/handler/history.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
2 changes: 1 addition & 1 deletion src/main/frontend/state.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 1f86f47

Please sign in to comment.