Browse Source

fix: stable keyboard when inserting and deleting blocks

Tienson Qin 9 months ago
parent
commit
ccb940dd06

+ 6 - 0
src/main/capacitor/components/app.cljs

@@ -83,6 +83,11 @@
     {:tab "settings"}
     {:tab "settings"}
     (ion/tabler-icon "settings" {:size 22}) "Settings")))
     (ion/tabler-icon "settings" {:size 22}) "Settings")))
 
 
+(rum/defc keep-keyboard-open
+  []
+  [:input.absolute.top-4.left-0.w-1.h-1.opacity-0
+   {:id "app-keep-keyboard-open-input"}])
+
 (rum/defc journals < rum/reactive
 (rum/defc journals < rum/reactive
   []
   []
   (let [show-action-bar? (fstate/sub :mobile/show-action-bar?)]
   (let [show-action-bar? (fstate/sub :mobile/show-action-bar?)]
@@ -195,6 +200,7 @@
        (settings/page)))
        (settings/page)))
      (bottom-tabs)
      (bottom-tabs)
 
 
+     (keep-keyboard-open)
      (ui-component/install-notifications)
      (ui-component/install-notifications)
      (ui-component/install-modals)
      (ui-component/install-modals)
 
 

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

@@ -2579,6 +2579,7 @@
 
 
 (defn- block-content-on-pointer-down
 (defn- block-content-on-pointer-down
   [e block block-id content edit-input-id config]
   [e block block-id content edit-input-id config]
+  (util/mobile-keep-keyboard-open)
   (when-not (or
   (when-not (or
              (:closed-values? config)
              (:closed-values? config)
              (> (count content) (state/block-content-max-length (state/get-current-repo))))
              (> (count content) (state/block-content-max-length (state/get-current-repo))))

+ 8 - 4
src/main/frontend/modules/outliner/pipeline.cljs

@@ -78,11 +78,15 @@
             (state/set-state! :editor/start-pos nil)
             (state/set-state! :editor/start-pos nil)
 
 
             (when-not (:graph/importing @state/state)
             (when-not (:graph/importing @state/state)
-              (when-let [editor-block-f @(:editor/edit-block-fn @state/state)]
-                (state/set-state! :editor/edit-block-fn nil)
-                (editor-block-f))
 
 
-              (react/refresh! repo affected-keys)
+              (let [edit-block-f @(:editor/edit-block-fn @state/state)
+                    delete-blocks? (= (:outliner-op tx-meta) :delete-blocks)]
+                (state/set-state! :editor/edit-block-fn nil)
+                (when delete-blocks?
+                  (util/mobile-keep-keyboard-open))
+                (react/refresh! repo affected-keys)
+                (when edit-block-f
+                  (util/schedule edit-block-f)))
 
 
               (when (and state/lsp-enabled?
               (when (and state/lsp-enabled?
                          (seq blocks)
                          (seq blocks)

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

@@ -1540,3 +1540,10 @@ Arg *stop: atom, reset to true to stop the loop"
      [^js target]
      [^js target]
      (when target
      (when target
        (some-> target (.querySelector ".CodeMirror") (.-CodeMirror)))))
        (some-> target (.querySelector ".CodeMirror") (.-CodeMirror)))))
+
+#?(:cljs
+   (defn mobile-keep-keyboard-open
+     []
+     (when mobile?
+       (when-let [node (gdom/getElement "app-keep-keyboard-open-input")]
+         (.focus node)))))