Browse Source

fix(ux): bad editor state related with the code editor

charlie 1 year ago
parent
commit
8e66551c5e
1 changed files with 9 additions and 8 deletions
  1. 9 8
      src/main/frontend/extensions/code.cljs

+ 9 - 8
src/main/frontend/extensions/code.cljs

@@ -464,14 +464,15 @@
                                    (reset! (:calc-atom state) (calc/eval-lines new-code))))))
         (.on editor "blur" (fn [cm e]
                              (when e (util/stop e))
-                             (when (or
-                                    (= :file (state/get-current-route))
-                                    (not (gobj/get cm "escPressed")))
-                               (code-handler/save-code-editor!))
-                             (state/set-block-component-editing-mode! false)
-                             (state/set-state! :editor/code-block-context nil)
-                             (vreset! *cursor-curr nil)
-                             (vreset! *cursor-prev nil)))
+                             (let [esc? (gobj/get cm "escPressed")]
+                               (when (or (= :file (state/get-current-route))
+                                       (not esc?))
+                                 (code-handler/save-code-editor!))
+                               (state/set-block-component-editing-mode! false)
+                               (state/set-state! :editor/code-block-context nil)
+                               (when (not esc?) (state/clear-edit!))
+                               (vreset! *cursor-curr nil)
+                               (vreset! *cursor-prev nil))))
         (.on editor "focus" (fn [_e]
                               (when (and
                                      (contains? #{:code} (:logseq.property.node/display-type code-block))