Bläddra i källkod

fix(mobile): don't switch to editing mode when scrolling

Tienson Qin 2 månader sedan
förälder
incheckning
060a0dd86b

+ 87 - 86
src/main/frontend/components/block.cljs

@@ -2629,93 +2629,94 @@
 
 (defn- block-content-on-pointer-down
   [e block block-id edit-input-id content config]
-  (let [target (.-target e)
-        selection-blocks (state/get-selection-blocks)
-        starting-block (state/get-selection-start-block-or-first)
-        mobile? (util/mobile?)
-        mobile-selection? (and mobile? (seq selection-blocks))
-        block-dom-element (util/rec-get-node target "ls-block")]
-    (if mobile-selection?
-      (let [ids (set (state/get-selection-block-ids))]
-        (if (contains? ids (:block/uuid block))
-          (do
-            (state/drop-selection-block! block-dom-element)
-            (when (= 1 (count ids))
-              (state/set-state! :mobile/show-action-bar? false)))
-          (state/conj-selection-block! block-dom-element)))
-      (when-not (or
-                 (:closed-values? config)
-                 (> (count content) (state/block-content-max-length (state/get-current-repo))))
-        (let [target (gobj/get e "target")
-              button (gobj/get e "buttons")
-              shift? (gobj/get e "shiftKey")
-              meta? (util/meta-key? e)
-              forbidden-edit? (target-forbidden-edit? target)
-              get-cursor-range #(some-> block-dom-element
-                                        (dom/by-class "block-content-inner")
-                                        first
-                                        util/caret-range)
-              mobile-range (when mobile? (get-cursor-range))]
-          (when-not forbidden-edit?
-            (util/mobile-keep-keyboard-open false))
-          (when (and (not forbidden-edit?) (contains? #{1 0} button))
-            (cond
-              (and meta? shift?)
-              (when-not (empty? selection-blocks)
-                (util/stop e)
-                (editor-handler/highlight-selection-area! block-id block-dom-element {:append? true}))
-
-              meta?
-              (do
-                (util/stop e)
-                (if (some #(= block-dom-element %) selection-blocks)
-                  (state/drop-selection-block! block-dom-element)
-                  (state/conj-selection-block! block-dom-element :down))
-                (if (empty? (state/get-selection-blocks))
-                  (state/clear-selection!)
-                  (state/set-selection-start-block! block-dom-element)))
-
-              (and shift? starting-block)
-              (do
-                (util/stop e)
-                (util/clear-selection!)
-                (editor-handler/highlight-selection-area! block-id block-dom-element))
-
-              shift?
-              (do
-                (util/clear-selection!)
-                (state/set-selection-start-block! block-dom-element))
+  (when-not @(:ui/scrolling? @state/state)
+    (let [target (.-target e)
+          selection-blocks (state/get-selection-blocks)
+          starting-block (state/get-selection-start-block-or-first)
+          mobile? (util/mobile?)
+          mobile-selection? (and mobile? (seq selection-blocks))
+          block-dom-element (util/rec-get-node target "ls-block")]
+      (if mobile-selection?
+        (let [ids (set (state/get-selection-block-ids))]
+          (if (contains? ids (:block/uuid block))
+            (do
+              (state/drop-selection-block! block-dom-element)
+              (when (= 1 (count ids))
+                (state/set-state! :mobile/show-action-bar? false)))
+            (state/conj-selection-block! block-dom-element)))
+        (when-not (or
+                   (:closed-values? config)
+                   (> (count content) (state/block-content-max-length (state/get-current-repo))))
+          (let [target (gobj/get e "target")
+                button (gobj/get e "buttons")
+                shift? (gobj/get e "shiftKey")
+                meta? (util/meta-key? e)
+                forbidden-edit? (target-forbidden-edit? target)
+                get-cursor-range #(some-> block-dom-element
+                                          (dom/by-class "block-content-inner")
+                                          first
+                                          util/caret-range)
+                mobile-range (when mobile? (get-cursor-range))]
+            (when-not forbidden-edit?
+              (util/mobile-keep-keyboard-open false))
+            (when (and (not forbidden-edit?) (contains? #{1 0} button))
+              (cond
+                (and meta? shift?)
+                (when-not (empty? selection-blocks)
+                  (util/stop e)
+                  (editor-handler/highlight-selection-area! block-id block-dom-element {:append? true}))
 
-              :else
-              (let [block (or (db/entity [:block/uuid (:block/uuid block)]) block)]
-                (editor-handler/clear-selection!)
-                (editor-handler/unhighlight-blocks!)
-                (p/do!
-                 (state/pub-event! [:editor/save-code-editor])
-
-                 (when-not (:block.temp/load-status (db/entity (:db/id block)))
-                   (db-async/<get-block (state/get-current-repo) (:db/id block) {:children? false}))
-
-                 (let [cursor-range (if mobile? mobile-range (get-cursor-range))
-                       block (db/entity (:db/id block))
-                       {:block/keys [title format]} block
-                       content (if (config/db-based-graph? (state/get-current-repo))
-                                 (:block/title block)
-                                 (->> title
-                                      (property-file/remove-built-in-properties-when-file-based
-                                       (state/get-current-repo) format)
-                                      (drawer/remove-logbook)))]
-
-                   (state/set-editing!
-                    edit-input-id
-                    content
-                    block
-                    cursor-range
-                    {:db (db/get-db)
-                     :move-cursor? false
-                     :container-id (:container-id config)}))
-
-                 (state/set-selection-start-block! block-dom-element))))))))))
+                meta?
+                (do
+                  (util/stop e)
+                  (if (some #(= block-dom-element %) selection-blocks)
+                    (state/drop-selection-block! block-dom-element)
+                    (state/conj-selection-block! block-dom-element :down))
+                  (if (empty? (state/get-selection-blocks))
+                    (state/clear-selection!)
+                    (state/set-selection-start-block! block-dom-element)))
+
+                (and shift? starting-block)
+                (do
+                  (util/stop e)
+                  (util/clear-selection!)
+                  (editor-handler/highlight-selection-area! block-id block-dom-element))
+
+                shift?
+                (do
+                  (util/clear-selection!)
+                  (state/set-selection-start-block! block-dom-element))
+
+                :else
+                (let [block (or (db/entity [:block/uuid (:block/uuid block)]) block)]
+                  (editor-handler/clear-selection!)
+                  (editor-handler/unhighlight-blocks!)
+                  (p/do!
+                   (state/pub-event! [:editor/save-code-editor])
+
+                   (when-not (:block.temp/load-status (db/entity (:db/id block)))
+                     (db-async/<get-block (state/get-current-repo) (:db/id block) {:children? false}))
+
+                   (let [cursor-range (if mobile? mobile-range (get-cursor-range))
+                         block (db/entity (:db/id block))
+                         {:block/keys [title format]} block
+                         content (if (config/db-based-graph? (state/get-current-repo))
+                                   (:block/title block)
+                                   (->> title
+                                        (property-file/remove-built-in-properties-when-file-based
+                                         (state/get-current-repo) format)
+                                        (drawer/remove-logbook)))]
+
+                     (state/set-editing!
+                      edit-input-id
+                      content
+                      block
+                      cursor-range
+                      {:db (db/get-db)
+                       :move-cursor? false
+                       :container-id (:container-id config)}))
+
+                   (state/set-selection-start-block! block-dom-element)))))))))))
 
 (rum/defc dnd-separator-wrapper < rum/reactive
   [block block-id top?]

+ 1 - 1
src/main/frontend/handler/common.cljs

@@ -53,6 +53,6 @@
                      (-> (util/app-scroll-container-node)
                          (gobj/get "scrollTop")))
                     (reset! *scroll-timer (js/setTimeout
-                                           (fn [] (state/set-state! :ui/scrolling? false)) 500)))
+                                           (fn [] (state/set-state! :ui/scrolling? false)) 150)))
         debounced-on-scroll (debounce on-scroll 100)]
     (.addEventListener element "scroll" debounced-on-scroll false)))

+ 7 - 1
src/main/mobile/components/app.cljs

@@ -2,10 +2,12 @@
   "App root"
   (:require ["../externals.js"]
             [frontend.components.journal :as journal]
+            [frontend.handler.common :as common-handler]
             [frontend.handler.user :as user-handler]
             [frontend.rum :as frum]
             [frontend.state :as state]
             [frontend.ui :as ui]
+            [frontend.util :as util]
             [logseq.shui.dialog.core :as shui-dialog]
             [logseq.shui.hooks :as hooks]
             [logseq.shui.popup.core :as shui-popup]
@@ -137,7 +139,11 @@
         *home (rum/use-ref nil)]
     (use-screen-size-effects!)
     (use-theme-effects! current-repo)
-    (hooks/use-effect! (fn [] (setup-sidebar-touch-swipe!)) [])
+    (hooks/use-effect!
+     (fn []
+       (setup-sidebar-touch-swipe!)
+       (when-let [element (util/mobile-page-scroll)]
+         (common-handler/listen-to-scroll! element))) [])
     (silkhq/depth-sheet-stack
      {:as-child true}
      (silkhq/depth-sheet-scenery-outlets

+ 4 - 11
yarn.lock

@@ -1442,13 +1442,6 @@
   dependencies:
     undici-types "~7.10.0"
 
-"@types/node@^20.9.0":
-  version "20.19.9"
-  resolved "https://registry.yarnpkg.com/@types/node/-/node-20.19.9.tgz#ca9a58193fec361cc6e859d88b52261853f1f0d3"
-  integrity sha512-cuVNgarYWZqxRJDQHEB58GEONhOK79QVR/qYx4S7kcUObQvUwvFnYxJuuHUKm2aieN9X3yZB4LZsuYNU1Qphsw==
-  dependencies:
-    undici-types "~6.21.0"
-
 "@types/normalize-package-data@^2.4.0":
   version "2.4.4"
   resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.4.tgz#56e2cc26c397c038fab0e3a917a12d5c5909e901"
@@ -10477,10 +10470,10 @@ undertaker@^1.2.1:
     object.reduce "^1.0.0"
     undertaker-registry "^1.0.0"
 
-undici-types@~7.8.0:
-  version "7.8.0"
-  resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-7.8.0.tgz#de00b85b710c54122e44fbfd911f8d70174cd294"
-  integrity sha512-9UJ2xGDvQ43tYyVMpuHlsgApydB8ZKfVYTsLDhXkFL/6gfkp+U8xTGdh8pMJv1SpZna0zxG1DwsKZsreLbXBxw==
+undici-types@~7.10.0:
+  version "7.10.0"
+  resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-7.10.0.tgz#4ac2e058ce56b462b056e629cc6a02393d3ff350"
+  integrity sha512-t5Fy/nfn+14LuOc2KNYg75vZqClpAiqscVvMygNnlsHBFpSXdJaYtXMcdNLpl/Qvc3P2cB3s6lOV51nqsFq4ag==
 
 unified@^9.1.0:
   version "9.2.2"