Browse Source

Revert "chore: no need to keep keyboard open on mobile"

This reverts commit 0d134cb4c5a0993ec1c7bbaa50d9700e688e2faa.
Tienson Qin 1 day ago
parent
commit
4b0c56a87a

+ 2 - 0
src/main/frontend/components/block.cljs

@@ -2680,6 +2680,8 @@
                                           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?)

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

@@ -768,6 +768,8 @@
       ;; exit editing mode
       :else
       (let [select? (= type :esc)]
+        (when (.closest (.-target e) ".block-content")
+          (util/mobile-keep-keyboard-open))
         (when-let [container (gdom/getElement "app-container")]
           (dom/remove-class! container "blocks-selection-mode"))
         (p/do!

+ 17 - 0
src/main/frontend/util.cljc

@@ -1484,6 +1484,23 @@ Arg *stop: atom, reset to true to stop the loop"
      (when target
        (some-> target (.querySelector ".CodeMirror") (.-CodeMirror)))))
 
+#?(:cljs
+   (defn get-keep-keyboard-input-el
+     ([] (get-keep-keyboard-input-el ""))
+     ([t]
+      (js/document.getElementById (str "keep-keyboard-open-input" t)))))
+
+#?(:cljs
+   (defn mobile-keep-keyboard-open
+     ([]
+      (mobile-keep-keyboard-open true))
+     ([schedule?]
+      (when (mobile?)
+        (let [f #(when-let [node (or (get-keep-keyboard-input-el "in-modal")
+                                     (get-keep-keyboard-input-el))]
+                   (.focus node))]
+          (if schedule? (schedule f) (f)))))))
+
 #?(:cljs
    (defn rtc-test?
      []

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

@@ -156,6 +156,7 @@
      (when show-action-bar?
        (selection-toolbar/action-bar))
      (shui-popup/install-popups)
+     (ui-component/keep-keyboard-virtual-input)
      (ui-component/install-notifications)
      (shui-toaster/install-toaster)
      (shui-dialog/install-modals)]))

+ 3 - 1
src/main/mobile/components/editor_toolbar.cljs

@@ -238,9 +238,11 @@
   (let [editing? (state/sub :editor/editing?)
         code-block? (state/sub :editor/code-block-context)
         quick-add? (mobile-state/quick-add-open?)
+        keep-open? (= "app-keep-keyboard-open-input"
+                      (some-> js/document.activeElement (.-id)))
         show? (and (util/mobile?)
                    (not code-block?)
-                   editing?)
+                   (or editing? keep-open?))
         actions (toolbar-actions quick-add?)]
     (when (mobile-util/native-ios?)
       (native-toolbar show? actions))))

+ 8 - 0
src/main/mobile/components/ui.cljs

@@ -18,6 +18,14 @@
     [:div#main-container.flex.flex-1
      [:div.w-full content]]]])
 
+(rum/defc keep-keyboard-virtual-input
+  ([] (keep-keyboard-virtual-input ""))
+  ([t]
+   [:input.absolute.top-4.left-0.w-1.h-1.opacity-0
+    {:id (str "keep-keyboard-open-input" t)
+     :auto-capitalize "sentences"
+     :auto-correct "true"}]))
+
 (rum/defc notification-clear-all
   []
   [:div.ui__notifications-content