diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 461623aa72..56a1e90604 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -175,12 +175,15 @@ (defn restore-cursor-pos! [id markup] (when-let [node (gdom/getElement (str id))] - (when-let [cursor-range (state/get-cursor-range)] - (when-let [range cursor-range] - (let [pos (state/get-editor-last-pos) - pos (or pos (diff/find-position markup range))] - (cursor/move-cursor-to node pos) - (state/clear-editor-last-pos!)))))) + (let [last-edit-block (state/get-last-edit-block) + current-edit-block (state/get-edit-block)] + (when-let [cursor-range (state/get-cursor-range)] + (when-let [range cursor-range] + (let [pos (when (= (:db/id last-edit-block) (:db/id current-edit-block)) + (state/get-editor-last-pos)) + pos (or pos (diff/find-position markup range))] + (cursor/move-cursor-to node pos) + (state/clear-editor-last-pos!))))))) (defn highlight-block! [block-uuid] diff --git a/src/main/frontend/state.cljs b/src/main/frontend/state.cljs index cc5ec670c2..e3d4f6753e 100644 --- a/src/main/frontend/state.cljs +++ b/src/main/frontend/state.cljs @@ -868,6 +868,8 @@ ([edit-input-id content block cursor-range] (set-editing! edit-input-id content block cursor-range true)) ([edit-input-id content block cursor-range move-cursor?] + (when-let [editing-block (get-edit-block)] + (swap! state assoc :editor/last-edit-block editing-block)) (when (and edit-input-id block (or (publishing-enable-editing?) @@ -886,7 +888,6 @@ (assoc :editor/block block :editor/editing? {edit-input-id true} - :editor/last-edit-block block :editor/last-key-code nil :cursor-range cursor-range)))) (when-let [input (gdom/getElement edit-input-id)] diff --git a/src/main/logseq/api.cljs b/src/main/logseq/api.cljs index 81b5ebf13e..5466290e25 100644 --- a/src/main/logseq/api.cljs +++ b/src/main/logseq/api.cljs @@ -523,8 +523,7 @@ (let [block (state/get-edit-block) block (or block (some-> (first (state/get-selection-blocks)) (.getAttribute "blockid") - (db-model/get-block-by-uuid))) - block (or block (state/get-last-edit-block))] + (db-model/get-block-by-uuid)))] (get_block (:db/id block) opts)))) (def ^:export get_previous_sibling_block