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

fix: can't select blocks after inserting/indenting a block

Tienson Qin 1 год назад
Родитель
Сommit
25bbbc7950
2 измененных файлов с 25 добавлено и 41 удалено
  1. 12 18
      src/main/frontend/components/block.cljs
  2. 13 23
      src/main/frontend/state.cljs

+ 12 - 18
src/main/frontend/components/block.cljs

@@ -823,21 +823,21 @@
                                                 :preview? true}))]))]
 
     (rum/use-effect!
-      (fn []
-        (if (some-> (rum/deref *el-wrap) (.closest "[data-radix-popper-content-wrapper]"))
-          (set-in-popup! true)
-          (set-in-popup! false)))
-      [])
+     (fn []
+       (if (some-> (rum/deref *el-wrap) (.closest "[data-radix-popper-content-wrapper]"))
+         (set-in-popup! true)
+         (set-in-popup! false)))
+     [])
 
     [:span {:ref *el-wrap}
      (if (boolean? in-popup?)
        (if (and (not (:preview? config))
-             (not in-popup?)
-             (or (not manual?) open?))
+                (not in-popup?)
+                (or (not manual?) open?))
          (popup-preview-impl children
-           {:visible? visible? :set-visible! set-visible!
-            :*timer *timer :*timer1 *timer1
-            :render preview-render :*el-popup *el-popup})
+                             {:visible? visible? :set-visible! set-visible!
+                              :*timer *timer :*timer1 *timer1
+                              :render preview-render :*el-popup *el-popup})
          children)
        children)]))
 
@@ -2699,7 +2699,6 @@
               :key (str "block-content-" uuid)
               :on-pointer-up (fn [e]
                                (when (and
-                                      (state/in-selection-mode?)
                                       (not (string/includes? content "```"))
                                       (not (gobj/get e "shiftKey"))
                                       (not (util/meta-key? e)))
@@ -3127,9 +3126,7 @@
       (let [node (.querySelector parent ".bullet-container")]
         (when doc-mode?
           (dom/remove-class! node "hide-inner-bullet"))))
-    (when (and
-           (state/in-selection-mode?)
-           (non-dragging? e))
+    (when (non-dragging? e)
       (when-let [container (gdom/getElement "app-container-wrapper")]
         (dom/add-class! container "blocks-selection-mode"))
       (editor-handler/highlight-selection-area! block-id {:append? true}))))
@@ -3140,10 +3137,7 @@
   (when doc-mode?
     (when-let [parent (gdom/getElement block-id)]
       (when-let [node (.querySelector parent ".bullet-container")]
-        (dom/add-class! node "hide-inner-bullet"))))
-  (when (and (non-dragging? e)
-             (not @*resizing-image?))
-    (state/into-selection-mode!)))
+        (dom/add-class! node "hide-inner-bullet")))))
 
 (defn- on-drag-and-mouse-attrs
   [block original-block uuid top? block-id *move-to']

+ 13 - 23
src/main/frontend/state.cljs

@@ -159,7 +159,6 @@
       :editor/raw-mode-block                 (atom nil)
       :editor/virtualized-scroll-fn          nil
 
-      :selection/mode                        (atom false)
       ;; Warning: blocks order is determined when setting this attribute
       :selection/blocks                      (atom [])
       :selection/start-block                 (atom nil)
@@ -1060,6 +1059,18 @@ Similar to re-frame subscriptions"
    (when block-id
      (sub :editor/content {:path-in-sub-atom block-id}))))
 
+(defn set-selection-start-block!
+  [start-block]
+  (set-state! :selection/start-block start-block))
+
+(defn get-selection-start-block
+  []
+  (or @(get @state :selection/start-block)
+      (when-let [edit-block (get-edit-block)]
+        (let [id (str "ls-block-" (:block/uuid edit-block))]
+          (set-selection-start-block! id)
+          id))))
+
 (defn get-cursor-range
   []
   @(:editor/cursor-range @state))
@@ -1128,14 +1139,6 @@ Similar to re-frame subscriptions"
   (when-let [input (get-input)]
     (util/get-selection-start input)))
 
-(defn get-selection-start-block
-  []
-  @(get @state :selection/start-block))
-
-(defn set-selection-start-block!
-  [start-block]
-  (set-state! :selection/start-block start-block))
-
 (defn get-selection-direction
   []
   @(:selection/direction @state))
@@ -1187,17 +1190,11 @@ Similar to re-frame subscriptions"
   ([blocks direction]
    (when (seq blocks)
      (let [blocks (vec (remove nil? blocks))]
-       (set-state! :selection/mode true)
        (set-selection-blocks-aux! blocks)
        (when direction (set-state! :selection/direction direction))))))
 
-(defn into-selection-mode!
-  []
-  (set-state! :selection/mode true))
-
 (defn state-clear-selection!
   []
-  (set-state! :selection/mode false)
   (set-state! :selection/blocks nil)
   (set-state! :selection/direction nil)
   (set-state! :selection/start-block nil)
@@ -1214,14 +1211,10 @@ Similar to re-frame subscriptions"
       (some-> (first (get-selection-blocks))
               (gobj/get "id"))))
 
-(defn in-selection-mode?
-  []
-  @(:selection/mode @state))
-
 (defn selection?
   "True sense of selection mode with valid selected block"
   []
-  (and (in-selection-mode?) (seq (get-selection-blocks))))
+  (seq (get-selection-blocks)))
 
 (defn conj-selection-block!
   [block-or-blocks direction]
@@ -1233,13 +1226,11 @@ Similar to re-frame subscriptions"
 
 (defn drop-selection-block!
   [block]
-  (set-state! :selection/mode true)
   (set-selection-blocks-aux! (-> (remove #(= block %) (get-unsorted-selection-blocks))
                                  vec)))
 
 (defn drop-selection-blocks-starts-with!
   [block]
-  (set-state! :selection/mode true)
   (let [blocks (get-unsorted-selection-blocks)
         blocks' (-> (take-while (fn [b] (not= (.-id b) (.-id block))) blocks)
                     vec
@@ -1250,7 +1241,6 @@ Similar to re-frame subscriptions"
   []
   (let [blocks @(:selection/blocks @state)
         blocks' (vec (butlast blocks))]
-    (set-state! :selection/mode true)
     (set-selection-blocks-aux! blocks')
     (last blocks)))