fix: remove spaces around CJK characters when auto-complete pages

close #5929
pull/7632/head
Tienson Qin 2022-12-07 22:49:31 +08:00 committed by Andelf
parent 72acd0f1d4
commit ef8b0db3dd
2 changed files with 10 additions and 8 deletions

View File

@ -335,11 +335,15 @@
(+ current-pos i)))
current-pos)
orig-prefix (subs edit-content 0 current-pos)
postfix (subs edit-content current-pos)
postfix (if postfix-fn (postfix-fn postfix) postfix)
space? (let [space? (when (and last-pattern orig-prefix)
(let [s (when-let [last-index (string/last-index-of orig-prefix last-pattern)]
(gp-util/safe-subs orig-prefix 0 last-index))]
(not
(or
(util/cjk-string? (str (last orig-prefix)))
(util/cjk-string? (str (first postfix)))
(and s
(string/ends-with? s "(")
(or (string/starts-with? last-pattern block-ref/left-parens)
@ -365,8 +369,6 @@
:else
(util/replace-last last-pattern orig-prefix value space?))
postfix (subs edit-content current-pos)
postfix (if postfix-fn (postfix-fn postfix) postfix)
new-value (cond
(string/blank? postfix)
prefix
@ -380,11 +382,7 @@
(or backward-pos 0))]
(when-not (string/blank? new-value)
(state/set-block-content-and-last-pos! id new-value new-pos)
(cursor/move-cursor-to input
(if (and (or backward-pos forward-pos)
(not= end-pattern page-ref/right-brackets))
new-pos
(inc new-pos)))))))
(cursor/move-cursor-to input new-pos)))))
(defn simple-insert!
[id value

View File

@ -537,6 +537,10 @@
(when-not not-space? " ")
(triml-without-newlines right)))))
(defn cjk-string?
[s]
(re-find #"[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f]" s))
;; Add documentation
(defn replace-first [pattern s new-value]
(if-let [first-index (string/index-of s pattern)]
@ -1437,7 +1441,7 @@
(defn memoize-last
"Different from core.memoize, it only cache the last result.
Returns a memoized version of a referentially transparent function. The
memoized version of the function cache the the last result, and replay when calls
memoized version of the function cache the the last result, and replay when calls
with the same arguments, or update cache when with different arguments."
[f]
(let [last-mem (atom nil)