feat: swap out caret_pos imp

This commit is contained in:
Weihua Lu
2021-06-09 18:46:50 +08:00
committed by Tienson Qin
parent 3cbf3b74be
commit 669dac7a09
4 changed files with 53 additions and 52 deletions

View File

@@ -1,5 +1,6 @@
(ns frontend.util.cursor
(:require [clojure.string :as string]
(:require [cljs-bean.core :as bean]
[clojure.string :as string]
[frontend.util :as util]
[goog.dom :as gdom]
[goog.object :as gobj]))
@@ -20,20 +21,25 @@
second
int)})
(defn- get-caret-pos
(defn get-caret-pos
[input]
(let [pos (.-selectionStart input)]
(let [pos (.-selectionStart input)
rect (bean/->clj (.. input (getBoundingClientRect) (toJSON)))]
(try
(-> (gdom/getElement "mock-text")
gdom/getChildren
array-seq
(nth pos)
mock-char-pos)
(catch js/Error _e
mock-char-pos
(assoc :rect rect))
(catch :default _e
(js/console.log "index error" _e)
{:pos pos
:rect rect
:left js/Number.MAX_SAFE_INTEGER
:top js/Number.MAX_SAFE_INTEGER}))))
(defn pos [input]
(when input
(.-selectionStart input)))