fix: caret pos

pull/3949/head
Tienson Qin 2022-01-19 23:12:27 +08:00
parent 73e0c9968a
commit 8d4f44a326
1 changed files with 16 additions and 15 deletions

View File

@ -29,21 +29,22 @@
If you only need character position, use `pos` instead. Do NOT call this." If you only need character position, use `pos` instead. Do NOT call this."
[input] [input]
(let [pos (util/get-selection-start input) (when input
rect (bean/->clj (.. input (getBoundingClientRect) (toJSON)))] (let [pos (util/get-selection-start input)
(try rect (bean/->clj (.. input (getBoundingClientRect) (toJSON)))]
(-> (gdom/getElement "mock-text") (try
gdom/getChildren (some-> (gdom/getElement "mock-text")
array-seq gdom/getChildren
(util/nth-safe pos) array-seq
mock-char-pos (util/nth-safe pos)
(assoc :rect rect)) mock-char-pos
(catch :default _e (assoc :rect rect))
(js/console.log "index error" _e) (catch :default _e
{:pos pos (js/console.log "index error" _e)
:rect rect {:pos pos
:left js/Number.MAX_SAFE_INTEGER :rect rect
:top js/Number.MAX_SAFE_INTEGER})))) :left js/Number.MAX_SAFE_INTEGER
:top js/Number.MAX_SAFE_INTEGER})))))
(defn pos [input] (defn pos [input]