Просмотр исходного кода

fix: cursor moves to main area when using keyboard to delete blocks

in sidebar
Tienson Qin 6 месяцев назад
Родитель
Сommit
4d112d242c

+ 0 - 1
src/main/frontend/extensions/code.cljs

@@ -481,7 +481,6 @@
                                      (contains? #{:code} (:logseq.property.node/display-type code-block))
                                      (not= (:block/uuid edit-block) (:block/uuid (state/get-edit-block))))
                                 (editor-handler/edit-block! (or code-block edit-block) :max {:container-id (:container-id config)}))
-                              (state/set-editing-block-dom-id! (:block-parent-id config))
                               (state/set-block-component-editing-mode! true)
                               (state/set-state! :editor/code-block-context
                                                 {:editor editor

+ 2 - 2
src/main/frontend/handler/editor.cljs

@@ -1260,7 +1260,7 @@
   (cond
     ;; when editing, quit editing and select current block
     (state/editing?)
-    (let [element (gdom/getElement (state/get-editing-block-dom-id))]
+    (when-let [element (state/get-editor-block-container)]
       (when element
         (p/do!
          (save-current-block!)
@@ -2641,7 +2641,7 @@
         {:block/keys [format uuid] :as block} (or block (state/get-edit-block))
         format (or format :markdown)
         repo (state/get-current-repo)
-        editing-block (gdom/getElement (state/get-editing-block-dom-id))
+        editing-block (state/get-editor-block-container)
         f (if up? util/get-prev-block-non-collapsed util/get-next-block-non-collapsed)
         sibling-block (f editing-block)
         sibling-block (or (when (and sibling-block (property-value-node? sibling-block))

+ 1 - 4
src/main/frontend/handler/editor/lifecycle.cljs

@@ -9,7 +9,7 @@
 
 (defn did-mount!
   [state]
-  (let [[{:keys [block-parent-id]} id] (:rum/args state)
+  (let [[_ id] (:rum/args state)
         content (state/get-edit-content)
         input (state/get-input)
         node (util/rec-get-node input "ls-block")
@@ -20,9 +20,6 @@
     (when container-id
       (state/set-state! :editor/container-id container-id))
 
-    (when block-parent-id
-      (state/set-editing-block-dom-id! block-parent-id))
-
     (when content
       (editor-handler/restore-cursor-pos! id content))
 

+ 1 - 3
src/main/frontend/handler/jump.cljs

@@ -99,9 +99,7 @@
         (editor-handler/expand-block! current-block-id))
       (let [f #(let [selected-block-or-editing-block (or (first (state/get-selection-blocks))
                                                          ;; current editing block
-                                                         (some-> (state/get-editing-block-dom-id)
-                                                                 js/document.getElementById
-                                                                 (util/rec-get-node ".ls-block")))
+                                                         (state/get-editor-block-container))
                      triggers (->> (if selected-block-or-editing-block
                                      (d/sel selected-block-or-editing-block ".jtrigger")
                                      (d/sel ".jtrigger"))

+ 6 - 9
src/main/frontend/state.cljs

@@ -154,7 +154,6 @@
       :editor/in-composition?                false
       :editor/content                        (atom {})
       :editor/block                          (atom nil)
-      :editor/block-dom-id                   (atom nil)
       :editor/set-timestamp-block            (atom nil) ;; click rendered block timestamp-cp to set timestamp
       :editor/last-input-time                (atom {})
       :editor/document-mode?                 document-mode?
@@ -1463,14 +1462,6 @@ Similar to re-frame subscriptions"
         (util/set-theme-light)
         (util/set-theme-dark)))))
 
-(defn set-editing-block-dom-id!
-  [block-dom-id]
-  (set-state! :editor/block-dom-id block-dom-id))
-
-(defn get-editing-block-dom-id
-  []
-  @(:editor/block-dom-id @state))
-
 (defn set-root-component!
   [component]
   (set-state! :ui/root-component component))
@@ -1930,6 +1921,12 @@ Similar to re-frame subscriptions"
   []
   @(:editor/args @state))
 
+(defn get-editor-block-container
+  []
+  (some-> (get-edit-input-id)
+          (gdom/getElement)
+          (util/rec-get-node "ls-block")))
+
 (defn set-page-blocks-cp!
   [value]
   (set-state! [:view/components :page-blocks] value))

+ 1 - 1
src/main/logseq/api.cljs

@@ -844,7 +844,7 @@
     (let [block (state/get-edit-block)
           block (or block
                     (some-> (or (first (state/get-selection-blocks))
-                                (gdom/getElement (state/get-editing-block-dom-id)))
+                                (state/get-editor-block-container))
                             (.getAttribute "blockid")
                             (db-model/get-block-by-uuid)))]
       (get_block (:block/uuid block) opts))))