fix: there's no auto-complete if the cursor moves back to [[]]

Related to #538
This commit is contained in:
Tienson Qin
2021-11-10 23:36:53 +08:00
parent 295a07a1a7
commit 829c8ebb8d
7 changed files with 200 additions and 118 deletions

View File

@@ -5,7 +5,8 @@
[goog.object :as gobj]
[lambdaisland.glogi :as log]
[cljs-bean.core :as bean]
[frontend.util :as util]))
[frontend.util :as util]
[frontend.text :as text]))
;; TODO: replace with diff-match-patch
(defn diff
@@ -33,17 +34,6 @@
(def inline-special-chars
#{\* \_ \/ \` \+ \^ \~ \$})
(defn- get-current-line-by-pos
[s pos]
(let [lines (string/split-lines s)
result (reduce (fn [acc line]
(let [new-pos (+ acc (count line))]
(if (>= new-pos pos)
(reduced line)
(inc new-pos)))) 0 lines)]
(when (string? result)
result)))
(defn- markdown-link?
[markup current-line pos]
(and current-line
@@ -75,7 +65,7 @@
:else
(recur r1 t2 (inc i1) i2))))
current-line (get-current-line-by-pos markup pos)]
current-line (text/get-current-line-by-pos markup pos)]
(cond
(and (= (util/nth-safe markup pos)
(util/nth-safe markup (inc pos))