enhance: click to edit should jump to the end of markdown link

This commit is contained in:
Tienson Qin
2021-11-04 23:25:07 +08:00
parent cb93927f3f
commit f4ac31f5cd

View File

@@ -44,6 +44,14 @@
(when (string? result)
result)))
(defn- markdown-link?
[markup current-line pos]
(and current-line
(= (util/nth-safe markup pos) "]")
(= (util/nth-safe markup (inc pos)) "(")
(string/includes? (subs current-line 0 pos) "[")
(string/includes? (subs current-line pos) ")")))
;; (find-position "** hello _w_" "hello w")
(defn find-position
[markup text]
@@ -66,7 +74,8 @@
(recur t1 r2 i1 (inc i2))
:else
(recur r1 t2 (inc i1) i2))))]
(recur r1 t2 (inc i1) i2))))
current-line (get-current-line-by-pos markup pos)]
(cond
(and (= (util/nth-safe markup pos)
(util/nth-safe markup (inc pos))
@@ -76,12 +85,15 @@
(contains? inline-special-chars (util/nth-safe markup pos))
(let [matched (->> (take-while inline-special-chars (util/safe-subs markup pos))
(apply str))
current-line (get-current-line-by-pos markup pos)
matched? (and current-line (string/includes? current-line (string/reverse matched)))]
(if matched?
(+ pos (count matched))
pos))
(markdown-link? markup current-line pos)
(let [idx (string/index-of (subs current-line pos) ")")]
(+ pos (inc idx)))
:else
pos))
(catch js/Error e