enhance(mobile): make editing into viewport when insert new line

pull/3547/head
Tienson Qin 2021-12-22 18:08:16 +08:00
parent 5b9c059b11
commit b2123d6d95
6 changed files with 27 additions and 11 deletions

View File

@ -20,6 +20,7 @@
[frontend.modules.shortcut.core :as shortcut]
[frontend.state :as state]
[frontend.ui :as ui]
[frontend.handler.ui :as ui-handler]
[frontend.util :as util]
[frontend.util.cursor :as cursor]
[frontend.util.keycode :as keycode]
@ -269,7 +270,8 @@
{:forward-pos 1})
;; TODO: should we add this focus step to `simple-insert!`?
(when-let [input (gdom/getElement parent-id)]
(.focus input)))}
(.focus input)
(ui-handler/try-to-editing-input-into-viewport!)))}
(ui/icon "arrow-back"
{:style {:fontSize ui/icon-size}})]]
[:div

View File

@ -2375,7 +2375,8 @@
(defn- keydown-new-line
[]
(insert "\n"))
(insert "\n")
(ui-handler/try-to-editing-input-into-viewport!))
(declare delete-and-update)

View File

@ -23,7 +23,7 @@
(.focus element)
(when (or (mobile-util/is-native-platform?)
(util/mobile?))
(js/setTimeout #(util/make-el-into-viewport element 60) 64))))
(util/make-el-into-viewport element 60))))
state)
(defn did-remount!

View File

@ -228,7 +228,7 @@
(defmethod handle :mobile/keyboard-did-show [[_]]
(when-let [input (state/get-input)]
(js/setTimeout #(util/make-el-into-viewport input 60) 64)))
(util/make-el-into-viewport input 60)))
(defn run!
[]

View File

@ -283,3 +283,10 @@
(defn open-new-window!
[]
(ipc/ipc "openNewWindow"))
(defn try-to-editing-input-into-viewport!
[]
(when-let [input (state/get-input)]
(if (or (mobile/is-native-platform?)
(util/mobile?))
(util/make-el-into-viewport input 60))))

View File

@ -1490,13 +1490,19 @@
#?(:cljs
(defn make-el-into-viewport
[^js/HTMLElement el offset]
(let [viewport-height (or (.-height js/window.visualViewport)
(.-clientHeight js/document.documentElement))
target-bottom (.-bottom (.getBoundingClientRect el))]
(when (> (+ target-bottom (or (safe-parse-int offset) 0))
viewport-height)
(.scrollIntoView el #js {:block "center" :behavior "smooth"})))))
([^js/HTMLElement el offset]
(make-el-into-viewport el offset true))
([^js/HTMLElement el offset async?]
(let [handle #(let [viewport-height (or (.-height js/window.visualViewport)
(.-clientHeight js/document.documentElement))
target-bottom (.-bottom (.getBoundingClientRect el))]
(when (> (+ target-bottom (or (safe-parse-int offset) 0))
viewport-height)
(.scrollIntoView el #js {:block "center" :behavior "smooth"})))]
(if async?
(js/setTimeout #(handle) 64)
(handle))))))
#?(:cljs
(defn sm-breakpoint?