fix: can't create blocks after using template

This commit is contained in:
Tienson Qin
2021-04-19 22:36:46 +08:00
parent 7d14759f77
commit 407d93e5ca
4 changed files with 60 additions and 55 deletions

View File

@@ -243,35 +243,35 @@
{:keys [last-pattern postfix-fn backward-pos forward-pos]
:or {last-pattern slash}
:as option}]
(let [input (gdom/getElement id)
edit-content (gobj/get input "value")
current-pos (:pos (util/get-caret-pos input))
prefix (subs edit-content 0 current-pos)
space? (when (and last-pattern prefix)
(let [s (when-let [last-index (string/last-index-of prefix last-pattern)]
(util/safe-subs prefix 0 last-index))]
(not (and s
(string/ends-with? s "(")
(or (string/starts-with? last-pattern "((")
(string/starts-with? last-pattern "[["))))))
prefix (if (string/blank? last-pattern)
(if space?
(util/concat-without-spaces prefix value)
(str prefix value))
(util/replace-last last-pattern prefix value space?))
postfix (subs edit-content current-pos)
postfix (if postfix-fn (postfix-fn postfix) postfix)
new-value (if space?
(util/concat-without-spaces prefix postfix)
(str prefix postfix))
new-pos (- (+ (count prefix)
(or forward-pos 0))
(or backward-pos 0))]
(state/set-block-content-and-last-pos! id new-value new-pos)
(util/move-cursor-to input
(if (or backward-pos forward-pos)
new-pos
(+ new-pos 1)))))
(when-let [input (gdom/getElement id)]
(let [edit-content (gobj/get input "value")
current-pos (:pos (util/get-caret-pos input))
prefix (subs edit-content 0 current-pos)
space? (when (and last-pattern prefix)
(let [s (when-let [last-index (string/last-index-of prefix last-pattern)]
(util/safe-subs prefix 0 last-index))]
(not (and s
(string/ends-with? s "(")
(or (string/starts-with? last-pattern "((")
(string/starts-with? last-pattern "[["))))))
prefix (if (string/blank? last-pattern)
(if space?
(util/concat-without-spaces prefix value)
(str prefix value))
(util/replace-last last-pattern prefix value space?))
postfix (subs edit-content current-pos)
postfix (if postfix-fn (postfix-fn postfix) postfix)
new-value (if space?
(util/concat-without-spaces prefix postfix)
(str prefix postfix))
new-pos (- (+ (count prefix)
(or forward-pos 0))
(or backward-pos 0))]
(state/set-block-content-and-last-pos! id new-value new-pos)
(util/move-cursor-to input
(if (or backward-pos forward-pos)
new-pos
(+ new-pos 1))))))
(defn simple-insert!
[id value