Pārlūkot izejas kodu

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

close #5929
Tienson Qin 2 gadi atpakaļ
vecāks
revīzija
ef8b0db3dd
2 mainītis faili ar 10 papildinājumiem un 8 dzēšanām
  1. 5 7
      src/main/frontend/commands.cljs
  2. 5 1
      src/main/frontend/util.cljc

+ 5 - 7
src/main/frontend/commands.cljs

@@ -335,11 +335,15 @@
                            (+ current-pos i)))
                            (+ current-pos i)))
                        current-pos)
                        current-pos)
           orig-prefix (subs edit-content 0 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)
           space? (let [space? (when (and last-pattern orig-prefix)
                                 (let [s (when-let [last-index (string/last-index-of orig-prefix last-pattern)]
                                 (let [s (when-let [last-index (string/last-index-of orig-prefix last-pattern)]
                                           (gp-util/safe-subs orig-prefix 0 last-index))]
                                           (gp-util/safe-subs orig-prefix 0 last-index))]
                                   (not
                                   (not
                                    (or
                                    (or
+                                    (util/cjk-string? (str (last orig-prefix)))
+                                    (util/cjk-string? (str (first postfix)))
                                     (and s
                                     (and s
                                          (string/ends-with? s "(")
                                          (string/ends-with? s "(")
                                          (or (string/starts-with? last-pattern block-ref/left-parens)
                                          (or (string/starts-with? last-pattern block-ref/left-parens)
@@ -365,8 +369,6 @@
 
 
                    :else
                    :else
                    (util/replace-last last-pattern orig-prefix value space?))
                    (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
           new-value (cond
                       (string/blank? postfix)
                       (string/blank? postfix)
                       prefix
                       prefix
@@ -380,11 +382,7 @@
                      (or backward-pos 0))]
                      (or backward-pos 0))]
       (when-not (string/blank? new-value)
       (when-not (string/blank? new-value)
         (state/set-block-content-and-last-pos! id new-value new-pos)
         (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!
 (defn simple-insert!
   [id value
   [id value

+ 5 - 1
src/main/frontend/util.cljc

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