Browse Source

fix: can't edit on iOS

Tienson Qin 4 years ago
parent
commit
b2b5acb6f1
3 changed files with 26 additions and 12 deletions
  1. 12 11
      src/main/frontend/components/block.cljs
  2. 1 1
      src/main/frontend/util.cljc
  3. 13 0
      src/main/frontend/utils.js

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

@@ -1341,7 +1341,7 @@
   (.stopPropagation e)
   (let [target (gobj/get e "target")
         button (gobj/get e "buttons")]
-    (when (= button 1)
+    (when (contains? #{1 0} button)
       (when-not (or (util/link? target)
                    (util/input? target)
                    (util/details-or-summary? target)
@@ -1353,16 +1353,17 @@
        (let [properties-hidden? (text/properties-hidden? properties)
              content (text/remove-level-spaces content format)
              content (if properties-hidden? (text/remove-properties! content) content)
-             block (db/pull [:block/uuid (:block/uuid block)])]
+             block (db/pull [:block/uuid (:block/uuid block)])
+             f #(let [cursor-range (util/caret-range (gdom/getElement block-id))]
+                  (state/set-editing!
+                   edit-input-id
+                   content
+                   block
+                   cursor-range))]
          ;; wait a while for the value of the caret range
-         (js/setTimeout
-          #(let [cursor-range (util/caret-range (gdom/getElement block-id))]
-             (state/set-editing!
-              edit-input-id
-              content
-              block
-              cursor-range))
-          5))
+         (if (util/ios?)
+           (f)
+           (js/setTimeout f 5)))
 
        (when-not (state/get-selection-start-block)
          (when block-id (state/set-selection-start-block! block-id)))))))
@@ -1397,7 +1398,7 @@
 (rum/defc block-content < rum/reactive
   [config {:block/keys [uuid title level body meta content marker dummy? page format repo children pre-block? properties collapsed? idx container block-refs-count scheduled scheduled-ast deadline deadline-ast repeated?] :as block} edit-input-id block-id slide?]
   (let [dragging? (rum/react *dragging?)
-        mouse-down-key (if (util/mobile?)
+        mouse-down-key (if (util/ios?)
                          :on-click
                          :on-mouse-down ; TODO: it seems that Safari doesn't work well with on-mouse-down
                          )

+ 1 - 1
src/main/frontend/util.cljc

@@ -37,7 +37,7 @@
 #?(:cljs
     (defn ios?
       []
-      (not (nil? (re-find #"iPad|iPhone|iPod" js/navigator.userAgent)))))
+      (utils/ios)))
 
 #?(:cljs
     (defn safari?

+ 13 - 0
src/main/frontend/utils.js

@@ -204,3 +204,16 @@ export const win32 = path => {
   // UNC paths are always absolute
   return Boolean(result[2] || isUnc);
 };
+
+export const ios = function () {
+  return [
+    'iPad Simulator',
+    'iPhone Simulator',
+    'iPod Simulator',
+    'iPad',
+    'iPhone',
+    'iPod'
+  ].includes(navigator.platform)
+  // iPad on iOS 13 detection
+    || (navigator.userAgent.includes("Mac") && "ontouchend" in document)
+}