chore: clean up and some docs

This commit is contained in:
Weihua Lu
2021-06-10 14:46:38 +08:00
committed by Tienson Qin
parent 7d8ff2f2b5
commit 24d75ccd26
4 changed files with 33 additions and 36 deletions

View File

@@ -22,6 +22,12 @@
int)})
(defn get-caret-pos
"Get caret offset position as well as input element rect.
This function is only used by autocomplete command or up/down command
where offset position is needed.
If you only need character position, use `pos` instead. Do NOT call this."
[input]
(let [pos (.-selectionStart input)
rect (bean/->clj (.. input (getBoundingClientRect) (toJSON)))]
@@ -44,6 +50,14 @@
(when input
(.-selectionStart input)))
(defn start? [input]
(and input (zero? (.-selectionStart input))))
(defn end? [input]
(and input
(= (count (.-value input))
(.-selectionStart input))))
(defn move-cursor-to [input n]
(.setSelectionRange input n n))