diff --git a/src/main/frontend/handler/history.cljs b/src/main/frontend/handler/history.cljs index 06aa313202..cbc48483bb 100644 --- a/src/main/frontend/handler/history.cljs +++ b/src/main/frontend/handler/history.cljs @@ -9,12 +9,13 @@ [logseq.db :as ldb])) (defn restore-cursor! - [{:keys [editor-cursors undo?]}] - (let [{:keys [block-uuid container-id start-pos end-pos]} (if undo? (first editor-cursors) (last editor-cursors))] + [{:keys [editor-cursors block-content undo?]}] + (let [{:keys [block-uuid container-id start-pos end-pos]} (if undo? (first editor-cursors) (or (last editor-cursors) (first editor-cursors))) + pos (if undo? (or start-pos end-pos) (or end-pos start-pos))] (when-let [block (db/pull [:block/uuid block-uuid])] - (editor/edit-block! block (or (when undo? start-pos) end-pos) + (editor/edit-block! block pos {:container-id container-id - :custom-content (:block/content block)})))) + :custom-content block-content})))) (comment (defn- get-route-data @@ -47,12 +48,12 @@ :block/uuid str)] (when (db-transact/request-finished?) + (state/set-editor-op! :undo) (util/stop e) (p/do! (state/set-state! [:editor/last-replace-ref-content-tx repo] nil) (editor/save-current-block!) (state/clear-editor-action!) - (state/set-block-op-type! nil) (let [^js worker @state/*db-worker] (reset! *last-request (.undo worker repo current-page-uuid-str)) (p/let [result @*last-request] @@ -69,6 +70,7 @@ :block/uuid str)] (when (db-transact/request-finished?) + (state/set-editor-op! :redo) (util/stop e) (state/clear-editor-action!) (let [^js worker @state/*db-worker] diff --git a/src/main/frontend/modules/outliner/pipeline.cljs b/src/main/frontend/modules/outliner/pipeline.cljs index 712a097039..4328a3cddb 100644 --- a/src/main/frontend/modules/outliner/pipeline.cljs +++ b/src/main/frontend/modules/outliner/pipeline.cljs @@ -7,25 +7,13 @@ [frontend.handler.editor :as editor-handler] [frontend.util :as util])) -(defn- get-tx-id - [tx-report] - (get-in tx-report [:tempids :db/current-tx])) - -(defn- update-current-tx-editor-cursor! - [tx-report] - (let [tx-id (get-tx-id tx-report) - editor-cursor @(:history/tx-before-editor-cursor @state/state)] - (state/update-state! :history/tx->editor-cursor - (fn [m] (assoc-in m [tx-id :before] editor-cursor))) - (state/set-state! :history/tx-before-editor-cursor nil))) - (defn invoke-hooks [{:keys [_request-id tx-meta tx-data deleted-block-uuids affected-keys blocks]}] ;; (prn :debug ;; :request-id request-id ;; :tx-meta tx-meta ;; :tx-data tx-data) - (let [{:keys [from-disk? new-graph? undo? redo? initial-pages? end?]} tx-meta + (let [{:keys [from-disk? new-graph? initial-pages? end?]} tx-meta repo (state/get-current-repo) tx-report {:tx-meta tx-meta :tx-data tx-data} @@ -52,10 +40,8 @@ {:db/id (:e datom) :block.temp/fully-loaded? true})) tx-data)] (concat update-blocks-fully-loaded tx-data)) - tx-data) - tx-report (d/transact! conn tx-data' tx-meta)] - (when-not (or undo? redo?) - (update-current-tx-editor-cursor! tx-report))) + tx-data)] + (d/transact! conn tx-data' tx-meta)) (when-not (:graph/importing @state/state) ;; safe to edit the next block now since other blocks (e.g. prev editing block) diff --git a/src/main/frontend/state.cljs b/src/main/frontend/state.cljs index b7950f2df0..4585400a64 100644 --- a/src/main/frontend/state.cljs +++ b/src/main/frontend/state.cljs @@ -308,9 +308,6 @@ :whiteboard/onboarding-tour? (or (storage/get :whiteboard-onboarding-tour?) false) :whiteboard/last-persisted-at {} :whiteboard/pending-tx-data {} - :history/tx-before-editor-cursor (atom nil) - ;; db tx-id -> editor cursor - :history/tx->editor-cursor (atom {}) :system/info {} ;; Whether block is selected :ui/select-query-cache (atom {}) @@ -2342,14 +2339,6 @@ Similar to re-frame subscriptions" (when-not (string/blank? page-name) (sub [:db/properties-changed-pages page-name]))) -(defn update-tx-after-cursor-state! - [] - (let [editor-cursor (get-current-edit-block-and-position) - max-tx-id (apply max (keys @(:history/tx->editor-cursor @state)))] - (when (and max-tx-id (nil? (:after (get @(:history/tx->editor-cursor @state) max-tx-id)))) - (update-state! :history/tx->editor-cursor - (fn [m] (assoc-in m [max-tx-id :after] editor-cursor)))))) - (defn update-favorites-updated! [] (update-state! :favorites/updated? inc)) diff --git a/src/main/frontend/worker/undo_redo.cljs b/src/main/frontend/worker/undo_redo.cljs index 5dcd96fab1..4fecbfe6c5 100644 --- a/src/main/frontend/worker/undo_redo.cljs +++ b/src/main/frontend/worker/undo_redo.cljs @@ -416,9 +416,13 @@ when undo this op, this original entity-map will be transacted back into db") (apply conj! redo-ops-to-push rev-ops))))) (when-let [rev-ops (not-empty (sort&merge-ops (persistent! redo-ops-to-push)))] (push-redo-ops repo page-block-uuid (vec (cons boundary rev-ops)))) - (let [editor-infos (filter #(= ::record-editor-info (first %)) ops)] + (let [editor-cursors (->> (filter #(= ::record-editor-info (first %)) ops) + (map second) + (reverse)) + block-content (:block/content (d/entity @conn [:block/uuid (:block-uuid (first editor-cursors))]))] {:undo? true - :editor-cursors (map second editor-infos)})) + :editor-cursors editor-cursors + :block-content block-content})) (when (empty-undo-stack? repo page-block-uuid) (prn "No further undo information") @@ -438,9 +442,12 @@ when undo this op, this original entity-map will be transacted back into db") (apply conj! undo-ops-to-push rev-ops))))) (when-let [rev-ops (not-empty (sort&merge-ops (persistent! undo-ops-to-push)))] (push-undo-ops repo page-block-uuid (vec (cons boundary rev-ops)))) - (let [editor-infos (filter #(= ::record-editor-info (first %)) ops)] + (let [editor-cursors (->> (filter #(= ::record-editor-info (first %)) ops) + (map second)) + block-content (:block/content (d/entity @conn [:block/uuid (:block-uuid (last editor-cursors))]))] {:redo? true - :editor-cursors (map second editor-infos)})) + :editor-cursors editor-cursors + :block-content block-content})) (when (empty-redo-stack? repo page-block-uuid) (prn "No further redo information")