enhance: jump to the end of ]] if not show double brackets

This commit is contained in:
Tienson Qin
2021-07-26 22:56:29 +08:00
parent f4a3d76658
commit 029af35e39

View File

@@ -4,7 +4,8 @@
["diff-match-patch" :as diff-match-patch]
[goog.object :as gobj]
[lambdaisland.glogi :as log]
[cljs-bean.core :as bean]))
[cljs-bean.core :as bean]
[frontend.util :as util]))
;; TODO: replace with diff-match-patch
(defn diff
@@ -33,24 +34,29 @@
(defn find-position
[markup text]
(try
(loop [t1 (-> markup string/lower-case seq)
t2 (-> text string/lower-case seq)
i1 0
i2 0]
(let [[h1 & r1] t1
[h2 & r2] t2]
(cond
(or (empty? t1) (empty? t2))
i1
(let [pos (loop [t1 (-> markup string/lower-case seq)
t2 (-> text string/lower-case seq)
i1 0
i2 0]
(let [[h1 & r1] t1
[h2 & r2] t2]
(cond
(or (empty? t1) (empty? t2))
i1
(= h1 h2)
(recur r1 r2 (inc i1) (inc i2))
(= h1 h2)
(recur r1 r2 (inc i1) (inc i2))
(#{\[ \space \]} h2)
(recur t1 r2 i1 (inc i2))
(#{\[ \space \]} h2)
(recur t1 r2 i1 (inc i2))
:else
(recur r1 t2 (inc i1) i2))))
:else
(recur r1 t2 (inc i1) i2))))]
(if (and (= (util/nth-safe markup pos)
(util/nth-safe markup (inc pos))
"]"))
(+ pos 2)
pos))
(catch js/Error e
(log/error :diff/find-position {:error e})
(count markup))))