mirror of
https://github.com/logseq/logseq.git
synced 2026-05-05 19:36:35 +00:00
fix: can't create blocks after using template
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user