Browse Source

perf: don't reinstall editor shortcuts

Tienson Qin 1 year ago
parent
commit
bcf2eb7e5e

+ 0 - 1
src/main/frontend/components/editor.cljs

@@ -742,7 +742,6 @@
                 (state/set-editor-args! (:rum/args state))
                 (state/set-editor-args! (:rum/args state))
                 state)}
                 state)}
   (mixins/event-mixin setup-key-listener!)
   (mixins/event-mixin setup-key-listener!)
-  (shortcut/mixin :shortcut.handler/block-editing-only)
   lifecycle/lifecycle
   lifecycle/lifecycle
   [state {:keys [format block parent-block on-hide]} id config]
   [state {:keys [format block parent-block on-hide]} id config]
   (let [content (state/sub-edit-content (:block/uuid block))
   (let [content (state/sub-edit-content (:block/uuid block))

+ 17 - 15
src/main/frontend/handler/editor.cljs

@@ -2554,19 +2554,21 @@
   [el]
   [el]
   (some? (dom/closest el ".single-block")))
   (some? (dom/closest el ".single-block")))
 
 
-(defn keydown-new-block-handler [state e]
-  (if (or (state/doc-mode-enter-for-new-line?) (inside-of-single-block (rum/dom-node state)))
-    (keydown-new-line)
-    (do
-      (.preventDefault e)
-      (keydown-new-block state))))
-
-(defn keydown-new-line-handler [state e]
-  (if (and (state/doc-mode-enter-for-new-line?) (not (inside-of-single-block (rum/dom-node state))))
-    (keydown-new-block state)
-    (do
-      (.preventDefault e)
-      (keydown-new-line))))
+(defn keydown-new-block-handler [e]
+  (let [state (get-state)]
+    (if (or (state/doc-mode-enter-for-new-line?) (inside-of-single-block (rum/dom-node state)))
+     (keydown-new-line)
+     (do
+       (.preventDefault e)
+       (keydown-new-block state)))))
+
+(defn keydown-new-line-handler [e]
+  (let [state (get-state)]
+    (if (and (state/doc-mode-enter-for-new-line?) (not (inside-of-single-block (rum/dom-node state))))
+     (keydown-new-block state)
+     (do
+       (.preventDefault e)
+       (keydown-new-line)))))
 
 
 (defn- select-first-last
 (defn- select-first-last
   "Select first or last block in viewpoint"
   "Select first or last block in viewpoint"
@@ -3271,13 +3273,13 @@
     nil))
     nil))
 
 
 (defn editor-delete
 (defn editor-delete
-  [_state e]
+  [e]
   (when (state/editing?)
   (when (state/editing?)
     (util/stop e)
     (util/stop e)
     (keydown-delete-handler e)))
     (keydown-delete-handler e)))
 
 
 (defn editor-backspace
 (defn editor-backspace
-  [_state e]
+  [e]
   (when (state/editing?)
   (when (state/editing?)
     (keydown-backspace-handler false e)))
     (keydown-backspace-handler false e)))
 
 

+ 2 - 1
src/main/frontend/modules/shortcut/core.cljs

@@ -157,7 +157,8 @@
            [:shortcut.handler/misc
            [:shortcut.handler/misc
             :shortcut.handler/editor-global
             :shortcut.handler/editor-global
             :shortcut.handler/global-non-editing-only
             :shortcut.handler/global-non-editing-only
-            :shortcut.handler/global-prevent-default])
+            :shortcut.handler/global-prevent-default
+            :shortcut.handler/block-editing-only])
        (map #(install-shortcut-handler! % {}))
        (map #(install-shortcut-handler! % {}))
        doall))
        doall))