|
|
@@ -1341,44 +1341,47 @@
|
|
|
(def keyboard-height (atom nil))
|
|
|
#?(:cljs
|
|
|
(defn scroll-editor-cursor
|
|
|
- [^js/HTMLElement el & {:keys [to-vw-one-quarter? to-vw-center?]}]
|
|
|
+ [^js/HTMLElement el & {:keys [to-vw-one-quarter?]}]
|
|
|
(when (and el (native-platform?))
|
|
|
(let [box-rect (.getBoundingClientRect el)
|
|
|
box-top (.-top box-rect)
|
|
|
box-bottom (.-bottom box-rect)
|
|
|
|
|
|
+ header-height (-> (gdom/getElementByClass "cp__header")
|
|
|
+ .-clientHeight)
|
|
|
+
|
|
|
main-node (app-scroll-container-node)
|
|
|
scroll-top (.-scrollTop main-node)
|
|
|
|
|
|
current-pos (get-selection-start el)
|
|
|
- cursor-top (some-> (gdom/getElement "mock-text")
|
|
|
+ mock-text (some-> (gdom/getElement "mock-text")
|
|
|
gdom/getChildren
|
|
|
array-seq
|
|
|
- (nth-safe current-pos)
|
|
|
- .-offsetTop)
|
|
|
+ (nth-safe current-pos))
|
|
|
+ offset-top (and mock-text (.-offsetTop mock-text))
|
|
|
+ offset-height (and mock-text (.-offsetHeight mock-text))
|
|
|
|
|
|
- cursor-y (if cursor-top (+ cursor-top box-top) box-bottom)
|
|
|
+ cursor-y (if offset-top (+ offset-top box-top offset-height 2) box-bottom)
|
|
|
vw-height (or (.-height js/window.visualViewport)
|
|
|
(.-clientHeight js/document.documentElement))
|
|
|
+ ;; mobile toolbar height: 40px
|
|
|
scroll (- cursor-y (- vw-height (+ @keyboard-height 40)))]
|
|
|
(cond
|
|
|
(and to-vw-one-quarter? (> cursor-y (* vw-height 0.4)))
|
|
|
(set! (.-scrollTop main-node) (+ scroll-top (- cursor-y (/ vw-height 4))))
|
|
|
|
|
|
- (and to-vw-center? (> cursor-y (/ vw-height 2)))
|
|
|
- (.scrollBy main-node (bean/->js {:top (- cursor-y (/ vw-height 2))}))
|
|
|
-
|
|
|
- (and (< cursor-y 86) (>= cursor-y 62))
|
|
|
- (.scrollBy main-node (bean/->js {:top -24}))
|
|
|
+ (and (< cursor-y (+ header-height offset-height 4)) ;; 4 is top+bottom padding for per line
|
|
|
+ (>= cursor-y header-height))
|
|
|
+ (.scrollBy main-node (bean/->js {:top (- (+ offset-height 4))}))
|
|
|
|
|
|
- (< cursor-y 56)
|
|
|
+ (< cursor-y header-height)
|
|
|
(let [_ (.scrollIntoView el true)
|
|
|
main-node (app-scroll-container-node)
|
|
|
scroll-top (.-scrollTop main-node)]
|
|
|
(set! (.-scrollTop main-node) (- scroll-top (/ vw-height 4))))
|
|
|
|
|
|
(> scroll 0)
|
|
|
- (set! (.-scrollTop main-node) (+ scroll-top 24))
|
|
|
+ (set! (.-scrollTop main-node) (+ scroll-top scroll))
|
|
|
|
|
|
:else
|
|
|
nil)))))
|