From f16e972709fefa284857f895b8aac5675bbe1423 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Fri, 21 Jun 2024 18:29:48 +0800 Subject: [PATCH] fix: wrong pos when pressing Backspace Editor's state including last pos and cursor range need to be cleared when callling block-handler/edit-block! --- src/main/frontend/handler/block.cljs | 1 + src/main/frontend/state.cljs | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/frontend/handler/block.cljs b/src/main/frontend/handler/block.cljs index c1b1b677c0..585a31528b 100644 --- a/src/main/frontend/handler/block.cljs +++ b/src/main/frontend/handler/block.cljs @@ -193,6 +193,7 @@ (when-not config/publishing? (p/do! (state/pub-event! [:editor/save-code-editor]) + (state/clear-edit! {:clear-editing-block? false}) (when-let [block-id (:block/uuid block)] (let [repo (state/get-current-repo) db-graph? (config/db-based-graph? repo) diff --git a/src/main/frontend/state.cljs b/src/main/frontend/state.cljs index 8075b95882..3ab7e72382 100644 --- a/src/main/frontend/state.cljs +++ b/src/main/frontend/state.cljs @@ -1346,15 +1346,21 @@ Similar to re-frame subscriptions" [] (set-state! :editor/last-saved-cursor {})) -(defn clear-edit! +(defn clear-cursor-range! [] + (set-state! :editor/cursor-range nil)) + +(defn clear-edit! + [& {:keys [clear-editing-block?] + :or {clear-editing-block? true}}] (clear-editor-action!) - (set-state! :editor/editing? {}) + (when clear-editing-block? + (set-state! :editor/editing? {}) + (set-state! :editor/block nil)) (set-state! :editor/start-pos nil) (clear-editor-last-pos!) - (set-state! :editor/cursor-range nil) + (clear-cursor-range!) (set-state! :editor/content {}) - (set-state! :editor/block nil) (set-state! :ui/select-query-cache {})) (defn into-code-editor-mode!