enhance: support list, markdown property, etc

This commit is contained in:
leizhe
2021-09-30 06:22:35 +09:00
committed by Tienson Qin
parent 9f32805d9d
commit 014f744641
6 changed files with 182 additions and 107 deletions

View File

@@ -82,6 +82,45 @@
pos (- pos n)]
(move-cursor-to input pos)))))
(defn- get-input-content&pos
[input]
[(gobj/get input "value")
(pos input)])
(defn line-beginning-pos
[input]
(let [[content pos] (get-input-content&pos input)]
(if (zero? pos) 0
(inc (string/last-index-of content \newline (dec pos))))))
(defn line-end-pos
[input]
(let [[content pos] (get-input-content&pos input)]
(or (string/index-of content \newline pos)
(count content))))
(defn beginning-of-line?
[input]
(let [[content pos] (get-input-content&pos input)]
(or (zero? pos)
(when-let [pre-char (subs content (dec pos) pos)]
(= pre-char \newline)))))
(defn end-of-line?
[input]
(let [[content pos] (get-input-content&pos input)]
(or (= pos (count content))
(when-let [next-char (subs content pos (inc pos))]
(= next-char \newline)))))
(defn move-cursor-to-line-end
[input]
(move-cursor-to input (line-end-pos input)))
(defn move-cursor-to-line-beginning
[input]
(move-cursor-to input (line-beginning-pos input)))
(defn move-cursor-to-end
[input]
(let [pos (count (gobj/get input "value"))]